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
Installation
Install the SDK and its required dependencies using Cargo:
cargo add smarty-rust-sdk
cargo add tokio --features full
cargo add serde_jsonImport 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
- US street API
- US autocomplete pro API
- US enrichment API
- US extract API
- US reverse geocoding API
- US ZIP Code API
- International address autocomplete API
- International street API
- International postal code API
All Rust SDK examples can be found on GitHub.