Skip to main content

ci codecov

PyCountryCodes

PyCountryCodes is a Python library for dealing with the ISO 3166-1 and ISO 3166-2 Standards in a simple way.

Installation

Use the package manager pip to install pycountrycodes.

pip install pycountrycodes

Usage

ISO 3166-1

from pycountrycodes import countries

# Go through the full list of countries available.
for country in countries:
    # prints the country name
    print(country.name)

# returns a Country object if the given criteria matches.
countries.get(name='United Kingdom')
countries.get(alpha_2='GB')
countries.get(alpha_3='GBR')

# returns a list of Country options fot the given query using fuzzy search.
countries.search('United Kingdom')

# returns a list of Country options fot the given query using fuzzy search 
# using the match_score_cutoff to filter the list and only return results with
# match_score greater or equal to 70.
countries.search('United Kingdom', match_score_cutoff=70)

ISO 3166-2

from pycountrycodes import subdivisions

# Go through the full list of subdivisions available.
for subdivisions in subdivisions:
    # prints the subdivision name
    print(subdivisions.name)

# returns a Subdivision object if the given criteria matches.
subdivisions.get(code='US-NY')

# returns a list of Subdivision objects if the given criteria matches.
# for name, type and country_code, this method will return a list of options since
# there can be multiples Subdivision objects with the same attribute values.
subdivisions.get(name='New York')  # returns all Subdivision where obj.name is 'New York'
subdivisions.get(type='Province')  # returns all Subdivision where obj.type is 'Province'
subdivisions.get(country_code='GB')  # returns all Subdivision where obj.country_code is 'GB'

# returns a list of Subdivisions options fot the given query using fuzzy search.
subdivisions.search('New York')

# returns a list of Subdivision options fot the given query using fuzzy search 
# using the match_score_cutoff to filter the list and only return results with
# match_score greater or equal to 70.
subdivisions.search('New York', match_score_cutoff=70)

ISO 4127

from pycountrycodes import currencies

# Go through the full list of currencies available.
for currency in currencies:
    # prints the currency name
    print(currency.name)

# returns a Currency object if the given criteria matches.
currencies.get(alpha_3='USD')

# returns a list of Currencies objects if the given criteria matches.
# for name this method will return a list of options since
# there can be multiples Currency objects with the same attribute values.
currencies.get(name='Leone')  # returns all Currency where obj.name is 'Leone'

# returns a list of Currencies options fot the given query using fuzzy search.
currencies.search('Dollar')

# returns a list of Currency options fot the given query using fuzzy search 
# using the match_score_cutoff to filter the list and only return results with
# match_score greater or equal to 70.
currencies.search('Dollar', match_score_cutoff=70)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Metadata

Release files for pycountrycodes 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycountrycodes 0.3.1
File Size Uploaded
pycountrycodes-0.3.1.tar.gz 76.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycountrycodes 0.3.1
File Interpreter ABI Platform
pycountrycodes-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 158.4 kB

Release files / pycountrycodes-0.3.1.tar.gz

Download URL pycountrycodes-0.3.1.tar.gz
Size 76.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4f2fd6406049580d33291fbfe6f133862b3bbc2ba808aee71a861eb6866d48fa
BLAKE2b-256 checksum
How to use checksums
500e6e00b09827b4a9324a0abdcbd0d4d115d9e6da390f552198ce95e754cfd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.8.12 Linux/5.18.10-76051810-generic

Release files / pycountrycodes-0.3.1-py3-none-any.whl

Download URL pycountrycodes-0.3.1-py3-none-any.whl
Size 81.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e2787d14376e66293453273e4287efdc2984394077177db822d26b9da5a5c8b
BLAKE2b-256 checksum
How to use checksums
9038678fb68c140fcb79c7b36d41344736b36c4568d2c0e03877ef61104b3efa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.8.12 Linux/5.18.10-76051810-generic

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page