Skip to main content
Pinpoint - Smarty's free user conference - October 22nd and 23rd Register now (opens in new tab)
Smarty

Smarty Rust SDK

Let's dive into the Rust client for Smarty's address verification, geocoding, autocomplete, and data enrichment APIs.

The Smarty Rust SDK lets you integrate address intelligence into your Rust applications with minimal boilerplate. Whether you're validating millions of addresses, enriching them with precise geocodes, or powering an autocomplete form, the SDK gives you a clear, Rust-native way to call every Smarty API.

Contents

  1. Installation
  2. Authentication
  3. Create an API client
  4. Create and send lookups
  5. Examine results
  6. More examples

Installation

Install the SDK and its required dependencies using Cargo:

cargo add smarty-rust-sdk
cargo add tokio --features full
cargo add serde_json

Import packages:

use smarty_rust_sdk::us_street_api::lookup::{Lookup, MatchStrategy};
use smarty_rust_sdk::us_street_api::client::USStreetAddressClient;
use smarty_rust_sdk::sdk::authentication::BasicAuthCredential;
use smarty_rust_sdk::sdk::batch::Batch;
use smarty_rust_sdk::sdk::options::OptionsBuilder;

Authentication

Smarty offers two kinds of credentials depending on the deployment context:

  • Server-side (backend, CLI, batch jobs): Use Auth ID + Auth Token (a Secret Key pair).
  • Client-side (browser, front-end, public UI): Use Auth Web + Auth Referer (a Website Key pair restricted by domain).

Access all keys through your Smarty account under Account → API Keys.

Store credentials as environment variables for security:

export SMARTY_AUTH_ID="your-auth-id"
export SMARTY_AUTH_TOKEN="your-auth-token"
export SMARTY_AUTH_WEB="your-auth-web"
export SMARTY_AUTH_REFERER="your-auth-referer"

For details on authentication and embedded vs. secret keys, see our authentication documentation.

Create an API client

The SDK offers different client types for each API.

Server-side client

Here's an example for us-street-api:

let authentication = BasicAuthCredential::new(
    std::env::var("SMARTY_AUTH_ID").expect("Missing SMARTY_AUTH_ID env variable"),
    std::env::var("SMARTY_AUTH_TOKEN").expect("Missing SMARTY_AUTH_TOKEN env variable"),
);

let options = OptionsBuilder::new(Some(authentication))
    .with_logging()
    .build();

let client = USStreetAddressClient::new(options)?;

Create and send lookups

Create lookups based on the addresses you want to validate. Here's an example for us-street-api:

let lookup = Lookup {
    street: "1600 Amphitheatre Pkwy".to_string(),
    last_line: "Mountain View, CA".to_string(),
    max_candidates: 10,
    match_strategy: MatchStrategy::Enhanced,
    ..Default::default()
};

let lookup2 = Lookup {
    street: "1 Rosedale Street, Baltimore, MD".to_string(),
    max_candidates: 8,
    match_strategy: MatchStrategy::Enhanced,
    ..Default::default()
};

let mut batch = Batch::default();
batch.push(lookup)?;
batch.push(lookup2)?;

Use the client you created earlier to send the batch:

client.send(&mut batch).await?;

Examine results

Review the results provided by the API:

US Street API results

for record in batch.records() {
    println!("{}", serde_json::to_string_pretty(&record.results)?);
}

More examples

All Rust SDK examples can be found on GitHub.

Ready to get started?

Share feedback
What kind?

Use this form to share ideas or feedback for improving our website and products. For help using or implementing a Smarty product, contact support.

This chat is powered by Help Scout. Chats are recorded. Privacy Policy