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

# 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.1.tar.gz (9.9 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.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: countries_meta-0.1.1.tar.gz
  • Upload date:
  • Size: 9.9 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.1.tar.gz
Algorithm Hash digest
SHA256 338b22975085cce75821c3eff1e46ef7b2817c46c1388be1ad6f8028ad098c36
MD5 c989eb6a5fc1335043fd2a8e5db14e6f
BLAKE2b-256 0284aa98585d1551fd57f38a79463e14498e4af6fc260a5f59bd49930460e02d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: countries_meta-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c97300bbe94048a7f0f91999c350b625e59e8000aeacd635eabf9c6b2992af87
MD5 a75285bb22ac85999aeab59da134ebea
BLAKE2b-256 b909e87f80624cddd6b2b8dab9edc416762bd3891541b49f7e619ba1ab7746e1

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