Skip to main content

countrystatecity-timezones

PyPI Python Version License Type Checked timezones timezones

Official Python package for timezone data — 400+ IANA timezones with country associations, GMT offsets, and time conversion utilities. Part of the countrystatecity ecosystem.

Installation

pip install countrystatecity-timezones

Quick Start

from countrystatecity_timezones import (
    get_all_timezones,
    get_timezones_by_country,
    get_timezone_by_zone_name,
    get_timezones_by_offset,
    search_timezones,
    convert_time,
)
from datetime import datetime

# Get all timezones
timezones = get_all_timezones()
# [Timezone(zoneName="Africa/Abidjan", gmtOffset=0, ...), ...]

# Get timezones for a country
us_timezones = get_timezones_by_country("US")
# [Timezone(zoneName="America/Adak", countryCode="US", ...), ...]

# Lookup by IANA zone name
tz = get_timezone_by_zone_name("America/New_York")
# Timezone(zoneName="America/New_York", gmtOffset=-18000, gmtOffsetName="UTC-05:00", ...)

# Filter by GMT offset (seconds)
utc_minus_5 = get_timezones_by_offset(-18000)

# Search by name or abbreviation
results = search_timezones("Eastern")

# Convert time between timezones
dt = datetime(2024, 1, 1, 12, 0, 0)
converted = convert_time(dt, "America/New_York", "Asia/Kolkata")
# datetime(2024, 1, 1, 22, 30, tzinfo=ZoneInfo("Asia/Kolkata"))

Data Model

class Timezone(BaseModel):
    zoneName: str        # IANA timezone name (e.g., "America/New_York")
    gmtOffset: int       # GMT offset in seconds (e.g., -18000)
    gmtOffsetName: str   # Human-readable offset (e.g., "UTC-05:00")
    abbreviation: str    # Timezone abbreviation (e.g., "EST")
    tzName: str          # Full timezone name (e.g., "Eastern Standard Time")
    countryCode: str     # ISO2 country code (e.g., "US")
    countryName: str     # Country name (e.g., "United States")

API Reference

Function Description
get_all_timezones() Get all timezone entries
get_timezones_by_country(code) Get timezones for an ISO2 country code
get_timezone_by_zone_name(name) Lookup by IANA zone name
get_timezones_by_offset(seconds) Filter by GMT offset in seconds
search_timezones(query) Search by zone name, full name, or abbreviation
convert_time(dt, from_tz, to_tz) Convert datetime between IANA timezones

License

ODbL-1.0 — see LICENSE.

Other Packages in this Ecosystem

Package Description
countrystatecity-countries 250+ countries, 5,000+ states, 150,000+ cities
countrystatecity-currencies Currency codes, names, and symbols for every country
countrystatecity-translations Country name translations in 18+ languages
countrystatecity-phonecodes International phone/dialing codes for 250+ countries
countrystatecity-regions Continents and geographic subregions 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_timezones-1.0.4.tar.gz (17.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_timezones-1.0.4-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file countrystatecity_timezones-1.0.4.tar.gz.

File metadata

File hashes

Hashes for countrystatecity_timezones-1.0.4.tar.gz
Algorithm Hash digest
SHA256 559fa869e4f04ffe018dab8ae610ce3ad3c6c113ed529ded6f37093c0fbc89f3
MD5 dc9d9b0a09081cc8f437f4b77b8b38ea
BLAKE2b-256 7446ea5c088a3ad0927d0985ee67e1ddee5295a7e74dd7c98a3c90bde0ca9eef

See more details on using hashes here.

File details

Details for the file countrystatecity_timezones-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for countrystatecity_timezones-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e8e10ec4ac10f0c2f0a0a218dce9c776ff4748d00cd415bc3b7fd434d0254bea
MD5 ff35a3a805f0bc1375773cbb7343b2e3
BLAKE2b-256 3cfcb7167941f97231ee798c48604e4521bb7492b91fbea0fb73e21f0b7e26b3

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.5

2 files

This release

1.0.4 This release

2 files

1.0.3

2 files

1.0.0

2 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