Python library for address geocoding and reverse geocoding. Provides a unified interface to multiple geocoding providers (Nominatim, Google Maps, Mapbox, etc.) using ProviderKit for provider management.
Project description
python-geoaddress
Geoaddress is a Python library for address geocoding and reverse geocoding. It provides a unified interface to multiple geocoding providers (Nominatim, Google Maps, Mapbox, etc.) using ProviderKit for provider management.
Installation
pip install geoaddress
For development:
pip install -e .
pip install -e ".[dev,lint,quality,security,test]"
Usage
Geoaddress provides a unified interface to multiple geocoding providers through ProviderKit.
Basic Usage
Search Addresses
from geoaddress import addresses_autocomplete
# Search for addresses using available providers
results = addresses_autocomplete("1600 Amphitheatre Parkway, Mountain View, CA")
# Results include addresses from all available providers
for result in results:
print(f"{result['text']} - {result['latitude']}, {result['longitude']}")
Reverse Geocoding
from geoaddress import reverse_geocode
# Convert coordinates to address
address = reverse_geocode(37.4224764, -122.0842499)
print(f"Address: {address['text']}")
print(f"City: {address['city']}")
print(f"Country: {address['country']}")
Provider Selection
You can specify which providers to use:
from geoaddress import addresses_autocomplete
# Use only Nominatim provider
results = addresses_autocomplete(
"Paris, France",
query_string="nominatim"
)
# Use multiple specific providers
results = addresses_autocomplete(
"Paris, France",
query_string="nominatim|photon"
)
Provider Configuration
Providers can be configured via environment variables or configuration files:
# Environment variables (provider-specific prefixes)
# NOMINATIM_USER_AGENT=my-app/1.0
# GOOGLE_MAPS_API_KEY=your-api-key
# MAPBOX_ACCESS_TOKEN=your-token
from geoaddress import addresses_autocomplete
# Providers automatically use environment variables
results = addresses_autocomplete("Paris, France")
Loading Providers from Configuration
from geoaddress import get_address_providers, addresses_autocomplete
# Load providers from JSON configuration
providers = get_address_providers(json="providers.json")
# Use specific providers
results = addresses_autocomplete("Paris, France", providers=providers)
Supported Providers
Free Providers (no API key required)
- Nominatim: OpenStreetMap-based geocoding
- Photon: Komoot's OpenStreetMap geocoding service
Paid/API key Providers
- Google Maps: Google's geocoding API
- Mapbox: Mapbox Geocoding API
- LocationIQ: LocationIQ Geocoding API
- OpenCage: OpenCage Geocoding API
- Geocode Earth: Geocode Earth API
- Geoapify: Geoapify Geocoding API
- Maps.co: Maps.co Geocoding API
- HERE: HERE Geocoding API
Address Format
All providers return addresses in a standardized format:
{
"text": "Full formatted address string",
"reference": "Backend reference ID (place ID)",
"address_line1": "Street number and name",
"address_line2": "Building, apartment, floor (optional)",
"city": "City name",
"postal_code": "Postal/ZIP code",
"state": "State/region/province",
"country": "Country name",
"country_code": "ISO country code (e.g., FR, US, GB)",
"latitude": 48.8566,
"longitude": 2.3522,
"confidence": 95.0,
"relevance": 100.0,
"backend": "Nominatim",
"backend_name": "nominatim",
"geoaddress_id": "nominatim-123456"
}
CLI Usage
Geoaddress includes a CLI for command-line usage:
# Search addresses
geoaddress address --query "Paris, France"
# Reverse geocoding
geoaddress reverse --lat 48.8566 --lon 2.3522
# Use specific provider
geoaddress address --query "Paris, France" --backend nominatim
Architecture
Geoaddress uses a provider-based architecture built on ProviderKit:
- Each geocoding service is implemented as a provider inheriting from
GeoaddressProvider GeoaddressProviderextendsProviderBasefrom ProviderKit- Providers are organized in the
providers/directory - Common functionality is shared through the base
GeoaddressProviderclass - Provider discovery and management is handled by ProviderKit
Environment Variables
ENVFILE_PATH
The ENVFILE_PATH environment variable allows you to automatically specify the path to a .env file to load when starting services.
Usage:
ENVFILE_PATH=.env.local ./service.py dev install-dev
ENSURE_VIRTUALENV
The ENSURE_VIRTUALENV environment variable allows you to automatically activate the .venv virtual environment if it exists.
Usage:
ENSURE_VIRTUALENV=1 ./service.py quality lint
Provider-Specific Variables
Each provider uses environment variables with specific prefixes:
NOMINATIM_USER_AGENT: User agent for Nominatim requestsGOOGLE_MAPS_API_KEY: Google Maps API keyMAPBOX_ACCESS_TOKEN: Mapbox access tokenLOCATIONIQ_API_KEY: LocationIQ API keyOPENCAGE_API_KEY: OpenCage API key- And more...
Use Cases
- Address search and autocomplete
- Geocoding addresses to coordinates
- Reverse geocoding coordinates to addresses
- Address validation and normalization
- Multi-provider address lookup with fallback
- Address data standardization across different geocoding services
- Integration with mapping and location-based applications
Development
Geoaddress uses clicommands for the CLI. See docs/ for project rules and guidelines.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file geoaddress-1.0.0.tar.gz.
File metadata
- Download URL: geoaddress-1.0.0.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
087de5e222e8bc232f7fe3e0977b62efe2de1affe67f12caac40f5c182cd1684
|
|
| MD5 |
b7d193ec88730f5720eb2899a5e1b04b
|
|
| BLAKE2b-256 |
4c0c8c5e141d4402a6b7137de5238bbd97f9961a5abfb32fd5c02bd14babc34d
|
File details
Details for the file geoaddress-1.0.0-py3-none-any.whl.
File metadata
- Download URL: geoaddress-1.0.0-py3-none-any.whl
- Upload date:
- Size: 34.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ebfa01e1135c3f5d10c9e00960c4894ad8aefaaeb3cdf9df0669df70792dfec
|
|
| MD5 |
ffbc13fe9806896dec8e67b8e1faf543
|
|
| BLAKE2b-256 |
6233f3648fdc57142a36b5caa12fdd1002956e10d7bbfeaea43f5dc8c876fa62
|