Skip to main content

countrystatecity-timezones

PyPI Python Version License Type Checked timezones timezones

Official Python package for 432 IANA timezones with country associations, GMT offsets, and time conversion utilities. Part of the countrystatecity ecosystem.

From offline prototype to production

This package provides a versioned offline snapshot. For regularly updated data, server-side search and filtering, field-selected responses, or managed availability and support, use the Country State City API.

Get a free API key · API docs · Pricing · Migration guide

Keep API keys in server-side environment variables, never in client-side code or source control.

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,308 states, 171,938 cities
countrystatecity-currencies 249 country/currency associations
countrystatecity-translations 4,724 translations in 19 languages
countrystatecity-phonecodes International phone/dialing codes for 250 countries
countrystatecity-regions Region and subregion associations for 250 countries
countrystatecity-postal-codes Postal/ZIP records 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.5.tar.gz (18.7 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.5-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for countrystatecity_timezones-1.0.5.tar.gz
Algorithm Hash digest
SHA256 6e3c2b380c320b2c60d08efa8ba6d22aa19678936ac9fad50527cce0e9c81c1c
MD5 d90eb47b8b2b5c2344d66d247ef11e95
BLAKE2b-256 06ece38bc1d8f65bb5e4e99842c59d311a2278fad84bf13a4319ebee64a6a4f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for countrystatecity_timezones-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 16314f3527a67daf3f63a63be7cd7822d174395628bcf825915b5cfd3a3f307b
MD5 a9ccadcf226a7f14a3f8a61a452eb86d
BLAKE2b-256 13e8c47c31d98477751b2512b91f0ad503161d7e8aa8fd843316390a1d563be8

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.5 This release

2 files

1.0.4

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