Skip to main content

Python SDK for the latlng.work geocoding and places API

Project description

latlng · Python SDK

Website PyPI Python License: MIT

The official Python SDK for latlng.work — fast, open-data geocoding and places API powered by OpenStreetMap + Overture Maps.

  • Forward geocoding — address/place name → coordinates
  • Reverse geocoding — coordinates → address
  • Places nearby — POIs around a lat/lon
  • Places search — full-text place search
  • Autosuggest — typeahead suggestions
  • Categories — browse available place types

Both sync and async clients included. httpx is the only dependency.


Installation

pip install latlng

Get an API keydash.latlng.work
Free tier: 3,000 geocodes/day. No credit card required.


Quick Start

from latlng import LatlngClient

# Get a free API key at https://dash.latlng.work/
client = LatlngClient(api_key="latlng_xxxxx")  # or omit for anonymous (rate-limited)

# Forward geocode
result = client.geocode("Eiffel Tower, Paris")
print(result.first.lat, result.first.lon)
# 48.8584 2.2945

# Reverse geocode
result = client.reverse(48.8584, 2.2945)
print(result.first.name, result.first.city)
# Eiffel Tower Paris

# Places nearby
places = client.places.nearby(lat=48.8584, lon=2.2945, radius=500)
for place in places:
    print(place.name, place.category, f"{place.distance_m}m")

# Full-text place search
results = client.places.search("Louvre", lat=48.8584, lon=2.2945)

# Autosuggest (typeahead)
suggestions = client.places.autosuggest("Eiff", lat=48.858, lon=2.294)

# All place categories
categories = client.places.categories()
for cat in categories:
    print(cat.category, cat.count)

Async Usage

import asyncio
from latlng import AsyncLatlngClient

async def main():
    async with AsyncLatlngClient(api_key="latlng_xxxxx") as client:
        result = await client.geocode("Tokyo")
        print(result.first.lat, result.first.lon)

        places = await client.places.nearby(lat=35.6762, lon=139.6503, radius=1000)
        for place in places:
            print(place.name)

asyncio.run(main())

API Reference

LatlngClient / AsyncLatlngClient

Constructor Arg Type Default Description
api_key str | None None API key (latlng_xxxxx). Anonymous if omitted.
base_url str https://api.latlng.work Override API base URL.
timeout float 10.0 HTTP timeout in seconds.

Geocoding

client.geocode(query, *, limit=5, lang=None, lat=None, lon=None)

Forward geocode a query string. Returns GeocodingResponse.

Param Type Description
query str Address or place name
limit int Max results (default 5)
lang str Language code (e.g. "en")
lat, lon float Bias results near this location

client.reverse(lat, lon, *, limit=1, lang=None)

Reverse geocode coordinates. Returns GeocodingResponse.

Places

client.places.nearby(lat, lon, *, radius=1000, type=None, limit=20)

POIs near a location. Returns NearbyResponse.

client.places.search(q, *, lat=None, lon=None, type=None, country=None, limit=20)

Full-text place search. Returns SearchResponse.

client.places.autosuggest(q, *, lat=None, lon=None, limit=10)

Typeahead suggestions. Returns AutosuggestResponse.

client.places.categories()

All available place categories. Returns CategoriesResponse.

Response Models

Model Key Fields
GeocodingResult lat, lon, name, city, country, postcode, state
Place id, name, lat, lon, category, distance_m, country, region, locality
Category category, count

All collection responses (GeocodingResponse, NearbyResponse, etc.) support iteration with for item in response.

Exceptions

Exception When
LatlngRateLimitError HTTP 429 — rate limit hit
LatlngAuthError HTTP 401/403 — bad API key
LatlngUnavailableError HTTP 503 — upstream down
LatlngAPIError Any other non-2xx error
from latlng import LatlngClient
from latlng.exceptions import LatlngRateLimitError

client = LatlngClient()
try:
    result = client.geocode("Berlin")
except LatlngRateLimitError:
    print("Rate limit hit — get a free key at https://dash.latlng.work/")

Rate Limits

Plan Geocode Reverse Places Period
Anonymous 30 10 10 /day
Free 3,000 300 500 /day
Pro 1,000,000 100,000 500,000 /month
Enterprise Unlimited Unlimited Unlimited /month

→ Get a free API key at dash.latlng.work


License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

latlng-0.1.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

latlng-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file latlng-0.1.0.tar.gz.

File metadata

  • Download URL: latlng-0.1.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.14.3 HTTPX/0.28.1

File hashes

Hashes for latlng-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4317aa8ccd3c0a97ea6b836877f7c81e8a7235c85f34620b3c2a17d808b1b498
MD5 8267fc278f142a03fd9d1e15db9f4eb1
BLAKE2b-256 049d9ee027958487f142bb31c6d8775f03f011f2e6e7fd12fa8166f10ad0000b

See more details on using hashes here.

File details

Details for the file latlng-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: latlng-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.14.3 HTTPX/0.28.1

File hashes

Hashes for latlng-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8774d819fc53fc61c89eb6102c92de995e05dc9ed03bcb08cd0260834feb7a6b
MD5 951e97ada2dfc59e21e62dfca423f2c4
BLAKE2b-256 780f9ba5ec5a9df9508bfb2483e053cda8792580eb4c080731ac6d3f2dc703e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page