Skip to main content

Python SDK for CSV2GEO Geocoding API — 461M+ addresses, 39 countries, 48+ endpoints. Forward, reverse, batch, places, boundaries (postcode → polygon, ancestors walk-up, children walk-down, consolidated cities), IP geolocation with county overlay, coverage, autocomplete. 3,000 free requests/day.

Project description

CSV2GEO Python SDK

PyPI version Python versions License: MIT

Official Python SDK for the CSV2GEO Geocoding API - fast, accurate geocoding powered by 461M+ addresses worldwide.

Installation

pip install csv2geo

Quick Start

from csv2geo import Client

# Initialize with your API key
client = Client("your_api_key")

# Forward geocoding (address → coordinates)
result = client.geocode("1600 Pennsylvania Ave, Washington DC")
if result:
    print(f"Lat: {result.lat}, Lng: {result.lng}")
    print(f"Address: {result.formatted_address}")

# Reverse geocoding (coordinates → address)
result = client.reverse(38.8977, -77.0365)
if result:
    print(f"Address: {result.formatted_address}")

Features

  • Forward geocoding - Convert addresses to coordinates
  • Reverse geocoding - Convert coordinates to addresses
  • Batch processing - Geocode up to 10,000 addresses per request
  • Auto-retry - Automatic retry on rate limits
  • Type hints - Full type annotations for IDE support

API Reference

Initialize Client

from csv2geo import Client

client = Client(
    api_key="your_api_key",
    base_url="https://csv2geo.com/api/v1",  # optional
    timeout=30,  # optional, seconds
    auto_retry=True,  # optional, retry on rate limit
)

Forward Geocoding

# Simple - returns best match or None
result = client.geocode("1600 Pennsylvania Ave, Washington DC")

# With country filter
result = client.geocode("123 Main St", country="US")

# Full response with all matches
response = client.geocode_full("1600 Pennsylvania Ave")
for result in response.results:
    print(f"{result.formatted_address}: {result.accuracy_score}")

Reverse Geocoding

# Simple - returns best match or None
result = client.reverse(38.8977, -77.0365)

# Full response with all matches
response = client.reverse_full(38.8977, -77.0365)

Batch Geocoding

# Geocode multiple addresses (up to 10,000)
addresses = [
    "1600 Pennsylvania Ave, Washington DC",
    "350 Fifth Avenue, New York, NY",
    "1 Infinite Loop, Cupertino, CA",
]

results = client.geocode_batch(addresses)
for response in results:
    if response.best:
        print(f"{response.query}: {response.best.lat}, {response.best.lng}")
    else:
        print(f"{response.query}: Not found")

Batch Reverse Geocoding

# Reverse geocode multiple coordinates
coordinates = [
    (38.8977, -77.0365),
    (40.7484, -73.9857),
]

results = client.reverse_batch(coordinates)
for response in results:
    if response.best:
        print(response.best.formatted_address)

GeocodeResult Object

result = client.geocode("1600 Pennsylvania Ave, Washington DC")

# Coordinates
result.lat           # 38.8977
result.lng           # -77.0365
result.location      # Location(lat=38.8977, lng=-77.0365)

# Address
result.formatted_address  # "1600 PENNSYLVANIA AVE NW, WASHINGTON, DC 20500, US"
result.accuracy           # "rooftop"
result.accuracy_score     # 1.0

# Components
result.components.house_number  # "1600"
result.components.street        # "PENNSYLVANIA AVE NW"
result.components.city          # "WASHINGTON"
result.components.state         # "DC"
result.components.postcode      # "20500"
result.components.country       # "US"

Error Handling

from csv2geo import Client, AuthenticationError, RateLimitError, InvalidRequestError

client = Client("your_api_key")

try:
    result = client.geocode("123 Main St")
except AuthenticationError as e:
    print(f"Invalid API key: {e.message}")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except InvalidRequestError as e:
    print(f"Invalid request: {e.message}")

Rate Limits

The client tracks rate limit headers automatically:

client.geocode("123 Main St")

print(client.rate_limit)            # Max requests per minute
print(client.rate_limit_remaining)  # Requests remaining
print(client.rate_limit_reset)      # Unix timestamp when limit resets

With auto_retry=True (default), the client automatically waits and retries when rate limited.

Context Manager

with Client("your_api_key") as client:
    result = client.geocode("123 Main St")
    print(result.lat, result.lng)
# Session automatically closed

Get Your API Key

Sign up at csv2geo.com to get your API key.

Documentation

Community & Support

License

MIT License - see LICENSE for details.

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

csv2geo-1.9.0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

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

csv2geo-1.9.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file csv2geo-1.9.0.tar.gz.

File metadata

  • Download URL: csv2geo-1.9.0.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for csv2geo-1.9.0.tar.gz
Algorithm Hash digest
SHA256 efca32daae5a388184740b2dbc754175c41bc06dabb04b1c1277e6da650a4ff6
MD5 d07272d71a7bfa5dc1182171e128301f
BLAKE2b-256 35e7a77506a68a973c0eac3a1e9ce9cf84054fa417a2f1ea98b10bb69930d3da

See more details on using hashes here.

File details

Details for the file csv2geo-1.9.0-py3-none-any.whl.

File metadata

  • Download URL: csv2geo-1.9.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for csv2geo-1.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 263b5c7db3e2fe12eec0c3f71869eafa15f1dc2dfc1213129ba13edb126e14c6
MD5 12908f84aa791fd4398f34bff4688ff2
BLAKE2b-256 27823b2ddba06baa1282e7f90ea04d8ceae21379c4512e8282f2e2df6f8ab647

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