Skip to main content

countrystatecity-regions

PyPI Python Version License Type Checked regions regions

Official Python package for region and subregion data — continents and geographic subregions for 250+ countries. Part of the countrystatecity ecosystem.

Installation

pip install countrystatecity-regions

Quick Start

from countrystatecity_regions import (
    get_all_regions,
    get_region_by_country,
    get_countries_by_region,
    get_countries_by_subregion,
    get_all_region_names,
    get_all_subregion_names,
    search_regions,
)

# Get all country-region entries
regions = get_all_regions()
# [CountryRegion(countryCode="AF", countryName="Afghanistan", region="Asia", subregion="Southern Asia"), ...]

# Get the region/subregion for a country
us = get_region_by_country("US")
# CountryRegion(countryCode="US", countryName="United States", region="Americas", subregion="Northern America")

# Get all countries in a region
asian_countries = get_countries_by_region("Asia")
# [CountryRegion(countryCode="AF", ...), CountryRegion(countryCode="CN", ...), ...]

# Get all countries in a subregion
south_asia = get_countries_by_subregion("Southern Asia")
# [CountryRegion(countryCode="AF", ...), CountryRegion(countryCode="IN", ...), ...]

# List distinct region/subregion names
regions_list = get_all_region_names()
# ["Africa", "Americas", "Asia", "Europe", "Oceania", "Polar"]

asia_subregions = get_all_subregion_names("Asia")
# ["Central Asia", "Eastern Asia", "South-eastern Asia", "Southern Asia", "Western Asia"]

# Search by country name, code, region, or subregion
results = search_regions("southern asia")

Data Model

class CountryRegion(BaseModel):
    countryCode: str          # ISO2 country code (e.g., "US")
    countryName: str          # Country name (e.g., "United States")
    region: Optional[str]     # Continent/region (e.g., "Americas")
    subregion: Optional[str]  # Geographic subregion (e.g., "Northern America")

API Reference

Function Description
get_all_regions() Get all country-region entries
get_region_by_country(code) Get the region/subregion for an ISO2 country code
get_countries_by_region(region) Get all countries in a region (e.g., "Asia")
get_countries_by_subregion(subregion) Get all countries in a subregion (e.g., "Southern Asia")
get_all_region_names() Get all distinct region names, sorted
get_all_subregion_names(region=None) Get all distinct subregion names, optionally filtered by region
search_regions(query) Search by country name, code, region, or subregion

License

ODbL-1.0 — see LICENSE.

Other Packages in this Ecosystem

Package Description
countrystatecity-countries 250+ countries, 5,000+ states, 150,000+ cities
countrystatecity-timezones 400+ IANA timezones with country associations and time conversion
countrystatecity-currencies Currency codes, names, and symbols
countrystatecity-translations Country name translations in 18+ languages
countrystatecity-phonecodes International phone/dialing codes for 250+ countries
countrystatecity-postal-codes Postal/ZIP codes and format validation for 125+ countries

Data sourced from countries-states-cities-database.


Made with ❤️ by dr5hn

Download files

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

Source Distribution

countrystatecity_regions-1.0.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

countrystatecity_regions-1.0.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file countrystatecity_regions-1.0.0.tar.gz.

File metadata

  • Download URL: countrystatecity_regions-1.0.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for countrystatecity_regions-1.0.0.tar.gz
Algorithm Hash digest
SHA256 39a4061c0aad32850c7728a59ecfcf1f3272c50f857597b6e85e71104a3444c6
MD5 7edfffb420133558037c41edaecc6c43
BLAKE2b-256 c1b4f2bb89468f5f664d56faf40ec8c2d09578faea818fc51bf87e0b7ceb1f11

See more details on using hashes here.

File details

Details for the file countrystatecity_regions-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for countrystatecity_regions-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e910b2f69f1c2a34c64a1c455d2081bd0616b45f696177d3b456efafb7f7519
MD5 ddf1770c2eb8a5418ee5cddc5f22e18e
BLAKE2b-256 54e66615c1267b081b0df10ff1282d56c40f6328a01e96ea91940a0b51ec4095

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 Sentry Error logging StatusPage Status page