Type-safe Python package for timezone data with 400+ timezones, country associations, GMT offsets, and time conversion utilities.
Project description
countrystatecity-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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file countrystatecity_timezones-1.0.0.tar.gz.
File metadata
- Download URL: countrystatecity_timezones-1.0.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ace165ebfeadda2f4b23b4bfb5ab07f50e6edab9e8cf9b89c54c9c03068657d
|
|
| MD5 |
071043f1ea2dcaf79ec0bebd1e959d46
|
|
| BLAKE2b-256 |
833fe8adb2bd4de1f737c2ccc94a15991d2f8a2afba1a54a75f2d5c38cb9d5f7
|
File details
Details for the file countrystatecity_timezones-1.0.0-py3-none-any.whl.
File metadata
- Download URL: countrystatecity_timezones-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fb142d0448485e4200ecf7f412f9cd31927c54d41a3e2d67cc6ca76acafe617
|
|
| MD5 |
3956706f77ad5760be85b9df278adba8
|
|
| BLAKE2b-256 |
1fb57d6e9993bd9c849080f1bad8ef6d26ab0b0f132709b8abf6982e6b863960
|