#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

#234 in Geospatial

Download history 1652/week @ 2024-03-31 1733/week @ 2024-04-07 1545/week @ 2024-04-14 2368/week @ 2024-04-21 3381/week @ 2024-04-28 3045/week @ 2024-05-05 2248/week @ 2024-05-12 2423/week @ 2024-05-19 1977/week @ 2024-05-26 1419/week @ 2024-06-02 1157/week @ 2024-06-09 1291/week @ 2024-06-16 792/week @ 2024-06-23 457/week @ 2024-06-30 819/week @ 2024-07-07 623/week @ 2024-07-14

2,722 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