Skip to main content

Type-safe Python package for timezone data with 400+ timezones, country associations, GMT offsets, and time conversion utilities.

Project description

countrystatecity-timezones

PyPI version Python versions

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.

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

countrystatecity_timezones-1.0.0.tar.gz (16.9 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.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for countrystatecity_timezones-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6ace165ebfeadda2f4b23b4bfb5ab07f50e6edab9e8cf9b89c54c9c03068657d
MD5 071043f1ea2dcaf79ec0bebd1e959d46
BLAKE2b-256 833fe8adb2bd4de1f737c2ccc94a15991d2f8a2afba1a54a75f2d5c38cb9d5f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for countrystatecity_timezones-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6fb142d0448485e4200ecf7f412f9cd31927c54d41a3e2d67cc6ca76acafe617
MD5 3956706f77ad5760be85b9df278adba8
BLAKE2b-256 1fb57d6e9993bd9c849080f1bad8ef6d26ab0b0f132709b8abf6982e6b863960

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