Skip to main content

A Python module to access general countries information including name, origin name, dial code, currency, capital, timezone, and current time.

Project description

countries-meta

A Python module to access general countries information including name, origin name, dial code, currency, capital, timezone, and current time.

Installation

pip install countries-meta

Usage

from countries_meta import Countries

countries = Countries()

# Get country by code
us = countries.get_by_code('US')
us = countries.get('US')
us = countries['US']
print(us.name)  # United States

# Get country by name
germany = countries.get_by_name('Germany')
print(germany.capital)  # Berlin

# Get country by origin name
fr = countries.get_by_origin_name('République française')
print(fr.dial_code)  # +33

# Get country by dial code
canada = countries.get_by_dial_code('+1')
print(canada.name)  # Canada

# Get country by currency code
japan = countries.get_by_currency_code('JPY')
print(japan.capital)  # Tokyo

# Filter countries by currency code
usd_countries = countries.filter_by_currency_code('USD')
print([c.name for c in usd_countries])

# Filter countries by region
european_countries = countries.filter_by_region('Europe')
print([c.name for c in european_countries])

# Access timezone info and current time
print(us.timezone)  # America/Washington
print(us.now)       # Current local time
print(us.time_offset)  # Offset in hours from UTC

# Convert to dict or JSON
print(us.to_dict())
print(us.to_json())

Classes

Country

  • Attributes: code, name, origin_name, dial_code, currency_code, currency_symbol, capital, timezone

  • Properties:

    • tzinfo: ZoneInfo object for the timezone
    • now: current datetime in the country's timezone
    • time_offset: UTC offset in hours
  • Methods:

    • to_dict(*keys): return dict representation
    • to_json(*keys): return JSON string

Countries

  • Iterable container of all countries

  • Methods to access countries:

    • get_by_code(code)
    • get_by_name(name)
    • get_by_origin_name(name)
    • get_by_dial_code(dial_code)
    • get_by_currency_code(currency_code)
    • filter_by_currency_code(currency_code)
    • filter_by_region(region)

License

MIT

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

countries_meta-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

countries_meta-0.1.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file countries_meta-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for countries_meta-0.1.0.tar.gz
Algorithm Hash digest
SHA256 047544153b47824a0944745163cc0b7073c40a48961fc7f00fd4c22f589dad00
MD5 395d04ed34f90ebfe693e70d816dcb87
BLAKE2b-256 2876c7e237d4afd9c4f4f9c6cd495215c6b7d2616caaa382cf5663c22e8dd6a4

See more details on using hashes here.

File details

Details for the file countries_meta-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for countries_meta-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 189d8fea50148d391b05c5dfe3fe8cfdc7f711198d16bfb66c80259a96638d36
MD5 9f5fe8fd37c4d847e317f2590388c2d9
BLAKE2b-256 1fd86681e76590de410a9cf846677391f37057c4f7a95a78fc78ebef9989dc9d

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