Registry / type-stubs / types-tzlocal

types-tzlocal

JSON →
library5.1.0.1pypypi✓ verified 23d ago

types-tzlocal provides static type annotations (stubs) for the `tzlocal` library, which is used to obtain the local timezone as a `tzinfo` object. The current version, 5.1.0.1, specifically targets `tzlocal` versions up to 5.1. Note that as of `tzlocal` version 5.2, the core library includes its own type annotations, making `types-tzlocal` redundant for newer versions of `tzlocal`. It is maintained as part of the `typeshed` project and receives updates aligned with `tzlocal` releases.

pip install types-tzlocal
INSTALL
IMPORT
SIG · TYPES-TZLOCAL
T
types-tzlocal
type-stubspythonv5.1.0.1
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.1.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_localzone
from tzlocal import get_localzone
from tzlocal-stubs import get_localzone

Demonstrates how to retrieve the local timezone `tzinfo` object and create a timezone-aware `datetime` object using `tzlocal`. It also shows how to get the timezone name, with a note about potential failures on some systems.

from datetime import datetime from tzlocal import get_localzone # Get the local timezone tzinfo object local_tz = get_localzone() print(f"Local timezone: {local_tz}") # Create a timezone-aware datetime object now_naive = datetime.now() now_aware = local_tz.localize(now_naive) print(f"Timezone-aware datetime: {now_aware}") # Get just the timezone name (may fail on some Unix systems) try: local_tz_name = get_localzone_name() print(f"Local timezone name: {local_tz_name}") except Exception as e: print(f"Could not get local timezone name: {e}")
Debug
Known issues
breakingWith tzlocal version 5.0, the `pytz_deprecation_shim` was removed. This means `tzlocal.get_localzone()` now exclusively returns `zoneinfo` objects, similar to version 3.0. If your application relies on `pytz` objects, you must remain on `tzlocal` version 4.x or adapt your code to `zoneinfo`'s API.
fix
Either pin 'tzlocal<5' if `pytz` compatibility is essential, or update your code to work with `zoneinfo.ZoneInfo` objects (standard in Python 3.9+).
affects: tzlocal >= 5.0
gotchaSince `tzlocal` version 5.2, the `tzlocal` library itself bundles its type annotations (stubs). If you are using `tzlocal` 5.2 or newer, `types-tzlocal` becomes redundant and should be uninstalled to avoid potential conflicts or unnecessary package overhead.
fix
Run `pip uninstall types-tzlocal` if your `tzlocal` version is 5.2 or higher.
affects: tzlocal >= 5.2
gotchaOn some Unix-like systems, if the timezone name is not properly configured (e.g., in `/etc/timezone` or via symlinks), `tzlocal.get_localzone_name()` might raise an error, while `tzlocal.get_localzone()` would still successfully return a `tzinfo` object. Unconfigured systems might default to UTC.
fix
Ensure your operating system's timezone configuration is correctly set up. If only the `tzinfo` object is needed, prefer `get_localzone()` over `get_localzone_name()`.
affects: All versions of tzlocal
deprecatedThe `pytz_deprecation_shim` was introduced in `tzlocal` 4.0 to restore partial `pytz` compatibility after `tzlocal` 3.0 switched to `zoneinfo` objects. This shim was then removed in `tzlocal` 5.0. Relying on it for `pytz` compatibility in `tzlocal` 4.x is a temporary measure and should be migrated away from.
fix
Migrate to using `zoneinfo.ZoneInfo` objects (native in Python 3.9+) or other modern timezone handling, or explicitly manage `pytz` directly if specific `pytz` features are required.
affects: tzlocal 4.x (usage of shim)
Upgrade
Version history
5.1.0.1latest on PyPI · released Oct 24, 2023
Audit
Dependencies
tzlocalrequiredThis package provides type stubs for the 'tzlocal' runtime library. 'tzlocal' itself requires 'tzdata'.
Agent activity
46 hits · last 30 days
node
40
OpenAI (training)
1
Resources
types-tzlocal — pip install types-tzlocal · libregistry