#wrapper #libpostal #thread-safe #initialization #high-level #address #normalization

libpostal-rust

High-level wrappers for libpostal address normalization (with locks to support thread-safe initialization)

2 releases

0.1.1 Feb 17, 2022
0.1.0 Feb 17, 2022

#190 in Geospatial

22 downloads per month
Used in geocode-csv

Apache-2.0 OR MIT

40MB
609K SLoC

C 572K SLoC // 0.0% comments Python 15K SLoC // 0.1% comments Shell 8K SLoC // 0.2% comments M4 7.5K SLoC // 0.2% comments Rust 5.5K SLoC // 0.0% comments SQL 1K SLoC // 0.2% comments OCaml 202 SLoC Automake 84 SLoC // 0.1% comments

libpostal-rust: Yet Another libpostal Wrapper

This is another set of high-level bindings for the libpostal library. Several other Rust wrappers for this library exist. This one includes the following features, which may or may not be available elsewhere:

  • No need to have libpostal installed.
  • Support for building static Rust binaries.
  • Support for thread-safe initialization of libpostal.
  • Support from cross-compiling from x86_64 Macs to aarch64 (Apple Silicon), for use with GitHub CI builders and similar setups.

API Documentation


lib.rs:

libpostal-rust: A high-level, threadsafe wrapper around libpostal

The open source C library libpostal provides support for parsing and normalizing addresses using an external language model trained on addresses around the world. We provide a high-level Rust wrapper around that library, in a way that it can be linked into your main Rust binary.

Note that you will need to use libpostal_data (included with libpostal) to download and install about 2GB of language model data:

sudo libpostal_data download all /usr/local/share/libpostal

Once this is done, you can parse addresses as follows:

use libpostal_rust::{ParseAddressOptions, parse_address};

let addr = "781 Franklin Ave Crown Heights Brooklyn NYC NY 11216 USA";
let opt = ParseAddressOptions::default();
let parsed = parse_address(addr, &opt).unwrap();
assert_eq!(parsed.get("state"), Some(&"ny".to_owned()));

You can turn parsed back into a nicely-formatted address (almost anywhere in the world) by using address-formatter's support for OpenCage address templates.

Dependencies