Skip to main content

A Python package for working with world cities, countries, regions database

Project description

AigeoDB

A Python package for working with world cities, countries, regions database. This package provides easy access to a comprehensive database of world locations.

About

Developed by Unrealos Inc. - We create innovative SaaS and PaaS solutions powered by AI for business. Our expertise includes:

  • AI-powered business solutions
  • SaaS platforms
  • PaaS infrastructure
  • Custom enterprise software

Features

  • Easy-to-use interface for querying geographical data
  • Built-in database downloader and updater
  • Support for searching cities, countries, and regions
  • Geolocation features (nearby cities search)
  • SQLAlchemy models for all database entities
  • Django integration with custom model fields

Installation

pip install aigeodb

Core Usage

Basic Example

from aigeodb import DatabaseManager

# Initialize the database manager
db = DatabaseManager()

# Search for cities
cities = db.search_cities("Moscow", limit=5)
for city in cities:
    print(f"{city.name}, {city.country_code}")

# Get country information
country = db.get_country_info("US")
print(country.name, country.iso2)

# Find nearby cities
nearby = db.get_nearby_cities(40.7128, -74.0060, radius_km=100)
for city in nearby:
    print(f"{city.name}, {city.state_code}")

API Reference

# DatabaseManager methods
db = DatabaseManager()

# Search cities by name
cities = db.search_cities("Moscow", limit=5)

# Get country information
country = db.get_country_info("US")

# Find nearby cities (simple usage)
cities = db.get_nearby_cities(
    latitude=40.7128, 
    longitude=-74.0060,
    radius_km=100,
    limit=10
)
for city in cities:
    print(f"{city.name}, {city.state_code}")

# Find nearby cities with distances
cities_with_distances = db.get_nearby_cities(
    latitude=40.7128,
    longitude=-74.0060,
    radius_km=100,
    limit=10,
    with_distance=True
)
for city, distance in cities_with_distances:
    print(f"{city.name}: {distance:.1f}km")

# Get cities by country
cities = db.get_cities_by_country("US")

# Get states/regions by country
states = db.get_states_by_country("US")

# Get database statistics
stats = db.get_statistics()

Database Content

The package includes:

  • Countries (250 records)
  • Regions (6 records)
  • Subregions (22 records)
  • States/Regions/Municipalities (5,038 records)
  • Cities/Towns/Districts (151,072 records)

Django Integration

If you're using Django, AigeoDB provides custom model fields with autocomplete support.

Setup

  1. Add to INSTALLED_APPS:
INSTALLED_APPS = [
    ...
    'aigeodb.django',
]
  1. Add URLs:
from django.urls import path, include

urlpatterns = [
    ...
    path('', include('aigeodb.django.urls')),  # URLs already include 'aigeodb/' prefix
]

Using Fields

from django.db import models
from aigeodb.django.fields import CityField, CountryField

class Location(models.Model):
    # Required fields
    city = CityField()
    country = CountryField()
    
    # Optional fields
    optional_city = CityField(null=True, blank=True)
    optional_country = CountryField(null=True, blank=True)

Admin Integration

from django.contrib import admin

@admin.register(Location)
class LocationAdmin(admin.ModelAdmin):
    list_display = ('get_city_name', 'get_country_name', 'get_optional_city_name')
    search_fields = ('city', 'country', 'optional_city', 'optional_country')
    
    def get_city_name(self, obj):
        city_data = obj.city.get_data()
        return f"{city_data['name']}, {city_data['country_code']}"
    
    def get_country_name(self, obj):
        country_data = obj.country.get_data()
        return country_data['name']
        
    def get_optional_city_name(self, obj):
        if obj.optional_city:
            city_data = obj.optional_city.get_data()
            return f"{city_data['name']}, {city_data['country_code']}"
        return '-'
    
    get_city_name.short_description = 'City'
    get_country_name.short_description = 'Country'
    get_optional_city_name.short_description = 'Optional City'

License

MIT License - see the LICENSE file for details.

Credits

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

aigeodb-0.1.1.tar.gz (13.5 MB view details)

Uploaded Source

Built Distribution

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

aigeodb-0.1.1-py2.py3-none-any.whl (13.7 MB view details)

Uploaded Python 2Python 3

File details

Details for the file aigeodb-0.1.1.tar.gz.

File metadata

  • Download URL: aigeodb-0.1.1.tar.gz
  • Upload date:
  • Size: 13.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for aigeodb-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c2b3162a406f0e520065c702e10a6683d8539acf97ef529baa5116a4ec90a9d8
MD5 93bc1e88c11071894a83a35fbd4f6401
BLAKE2b-256 975e0efe2e67d8ca347b3fe75e09acaff38a59928ff09f99a9df7e5071f1f447

See more details on using hashes here.

File details

Details for the file aigeodb-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: aigeodb-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.7 MB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for aigeodb-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 157b70d51257e86c4b2f77609fd77d28a2fb335047e8f2b393b3c6f3d8d5755e
MD5 e6ceee90509261dbc47f1247a9fd16ef
BLAKE2b-256 d9f3915c356244163905b8cae9a18aaba9a43f48d3d1f41880c8a2a300dc5898

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