Return useful information for every country in the ISO 3166 standard.
Project description
Country Data Management
A Python package for managing and retrieving country-related data, including country information, subdivisions, and translated country names.
Features
- Retrieve country data using ISO country codes
- Access country subdivisions (states, provinces, etc.)
- Get translated country names in different languages
- Handle data from JSON files stored in a structured directory format
Installation
pip install country-registry
Usage
Initialize the Client
from countries_data import CountriesData
client = CountriesData()
Get Country Data
from countries_data import CountriesData
client = CountriesData()
# Get data for a specific country using ISO code
country_data = client.get_country_data_by_code("US")
Get Subdivisions
from countries_data import CountriesData
client = CountriesData()
# Get all subdivisions for a country as list
subdivisions = client.get_country_subdivisions_by_code("US")
# Get a specific subdivision by code
subdivision = client.get_country_subdivision_by_codes("US", "CA")
Get Translations
from countries_data import CountriesData
client = CountriesData()
# Get all country names in a specific language
spanish_names = client.get_translated_countries_names_by_lang_code("es")
# Get a specific country name in a language
spanish_name = client.get_translated_country_name_by_codes("es", "US")
Data Format
Country Data
The country data JSON files should follow this structure:
{
"US": {
"address_format": "{{recipient}}\n{{street}}\n{{city}} {{region_short}} {{postalcode}}\n{{country}}",
"alpha2": "US",
"alpha3": "USA",
"continent": "North America",
"country_code": "1",
"currency_code": "USD",
"distance_unit": "mi",
"gec": "US",
"geo": {
"latitude": 38.8833,
"longitude": -77.0167,
"max_latitude": 71.5388001,
"max_longitude": -66.885417,
"min_latitude": 18.7763,
"min_longitude": 170.5957,
"bounds": {
"northeast": {
"lat": 71.5388001,
"lng": -66.885417
},
"southwest": {
"lat": 18.7763,
"lng": 170.5957
}
}
},
"international_prefix": "011",
"ioc": "USA",
"iso_long_name": "The United States of America",
"iso_short_name": "United States",
"languages_official": ["en"],
"languages_spoken": ["en", "es"],
"national_destination_code_lengths": [3],
"national_number_lengths": [10],
"national_prefix": "1",
"nationality": "American",
"number": "840",
"postal_code": true,
"postal_code_format": "\\d{5}(-\\d{4})?",
"region": "Americas",
"start_of_week": "sunday",
"subregion": "Northern America",
"un_locode": "US",
"un_member": true,
"unofficial_names": ["United States", "USA", "United States of America"],
"vat_rates": {
"standard": null,
"reduced": [],
"super_reduced": null,
"parking": null
},
"vehicle_registration_code": "USA",
"world_region": "AMER"
}
}
Subdivision Data
The subdivision data JSON files should follow this structure:
{
"CA": {
"name": "California",
"code": "CA",
"unofficial_names": ["CA", "Calif."],
"geo": {
"latitude": 36.778261,
"longitude": -119.4179324,
"max_latitude": 42.009518,
"max_longitude": -114.131211,
"min_latitude": 32.528832,
"min_longitude": -124.482003,
"bounds": {
"northeast": {
"lat": 42.009518,
"lng": -114.131211
},
"southwest": {
"lat": 32.528832,
"lng": -124.482003
}
}
},
"translations": {
"en": "California",
"af": "Kalifornië",
"ar": "كاليفورنيا",
"az": "Kaliforniya",
"be": "Каліфорнія",
"bg": "Калифорния",
"ca": "Califòrnia",
"cs": "Kalifornie",
"da": "Californien",
"de": "Kalifornien",
"es": "California",
"et": "California",
"eu": "Kalifornia",
"fa": "کالیفرنیا",
"fi": "Kalifornia",
"fr": "Californie",
"he": "קליפורניה",
"hy": "Կալիֆորնիա",
"id": "California",
"it": "California",
"ja": "カリフォルニア州",
"ka": "კალიფორნია",
"ko": "캘리포니아",
"lt": "Kalifornija",
"lv": "Kalifornija",
"ms": "California",
"nb": "California",
"nl": "Californië",
"pl": "Kalifornia",
"pt": "Califórnia",
"ro": "California",
"ru": "Калифорния",
"sr": "Калифорнија",
"sv": "Kalifornien",
"tr": "Kaliforniya",
"uk": "Каліфорнія",
"ur": "کیلیفورنیا",
"vi": "California",
"zh": "加利福尼亚州",
"ceb": "California",
"sr_Latn": "Kalifornija",
"ccp": "কেলিফোর্নিয়া",
"hu": "Kalifornia",
"kk": "Калифорния",
"mk": "Калифорнија",
"no": "California",
"cy": "California",
"el": "Καλιφόρνια",
"mn": "Калифорни",
"ta": "கலிபோர்னியா"
},
"comments": null,
"type": "state"
}
}
Translation Data
The translation files should follow this structure:
{
"US": "Estados Unidos",
"CA": "Canadá",
"MX": "México"
}
Error Handling
The package includes robust error handling:
- Returns
Nonefor non-existent country codes - Returns
Nonefor non-existent subdivision codes - Returns empty list
[]for countries without subdivisions - Returns empty dict
{}for missing translation files - Logs errors using the
logurulogger
Dependencies
- Python 3.6+
- loguru
- pathlib
License
MIT License
Copyright (c) 2024
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 countries_data-0.1.5.tar.gz.
File metadata
- Download URL: countries_data-0.1.5.tar.gz
- Upload date:
- Size: 2.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83c6ba718a0574b976c5d5f0002ddaa860eeb210b3e31f6fd36154318cdb3655
|
|
| MD5 |
cf155d4052d8630b0474d1c8d8243010
|
|
| BLAKE2b-256 |
f6a08dd2bfede26797958c907d0a9c7c3b8c5b3730dbf048370145046d494194
|
File details
Details for the file countries_data-0.1.5-py3-none-any.whl.
File metadata
- Download URL: countries_data-0.1.5-py3-none-any.whl
- Upload date:
- Size: 2.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45fa114ee37a898c7fbb771b47360425b0340eafb6d9daacdc44eb9bf1495146
|
|
| MD5 |
3bb45bc0c6c16b91d643deef514d9b52
|
|
| BLAKE2b-256 |
d017b4c5523d9f9a0200263b310597b4165baec5a10cd9343fe6d0e414a1c355
|