Registry / serialization / tzlocal

tzlocal

JSON →
library5.4.4pypypi✓ verified 26d ago

A Python module that provides the local time zone information as a tzinfo object. Current version: 5.3.1, released on March 5, 2025. Maintained under the MIT License. Requires Python 3.9 or higher. Release cadence: approximately every 6 months.

pip install tzlocal
INSTALL
IMPORT
SIG · TZLOCAL
T
tzlocal
serializationpythonv5.4.4
Install
1.6s avg
Import
42ms
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.4.4 · 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.044s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.040s · 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
Ensure correct import path to access the function

Retrieve and print the local time zone information.

from tzlocal import get_localzone local_timezone = get_localzone() print(local_timezone)
Debug
Known issues
breakingVersion 5.0 removed pytz_deprecation_shim, returning only zoneinfo objects. For pytz compatibility, use version 4.0.
fix
Downgrade to version 4.0 for pytz compatibility.
affects: 5.0
gotchaget_localzone_name() may raise an error if no time zone name is configured on Unix systems. Use get_localzone() if only the tzinfo object is needed.
fix
Use get_localzone() when time zone name is unavailable.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'tzlocal'
The 'tzlocal' package is not installed in the current Python environment.
fix
Install the package using pip: `pip install tzlocal`
ERROR: Package 'tzlocal' requires a different Python version: X.Y.Z. Expected '>=3.9'
Attempting to install or use `tzlocal` version 5.3.1 (which requires Python 3.9 or higher) with an older Python interpreter.
fix
Upgrade your Python interpreter to version 3.9 or higher, or use an older `tzlocal` version compatible with your Python (though this is not recommended).
AttributeError: 'ZoneInfo' object has no attribute 'localize'
This error occurs when trying to use the `localize` method (common with `pytz` timezone objects) on a `zoneinfo.ZoneInfo` object, which is returned by `tzlocal.get_localzone()` from version 4.0 onwards. `zoneinfo` objects do not have a `localize` method.
fix
Use `datetime.datetime.replace()` or `datetime.datetime.astimezone()` to make a naive datetime object timezone-aware:
```python
import datetime
from tzlocal import get_localzone

local_tz = get_localzone()
naive_dt = datetime.datetime.now() # naive datetime
aware_dt = naive_dt.replace(tzinfo=local_tz)
# Or, to convert an already aware datetime from one zone to another:
# dt_utc = datetime.datetime.now(datetime.timezone.utc)
# aware_dt_local = dt_utc.astimezone(local_tz)
```
ModuleNotFoundError: No module named 'tzlocal.get_localzone'
The `get_localzone` function is directly available under the `tzlocal` module, not as a submodule.
fix
Import the function directly from the `tzlocal` module:
```python
from tzlocal import get_localzone
```
Upgrade
Version history
5.4.4latest on PyPI · released Jun 29, 2026
Audit
Dependencies
pytzrequiredRequired for time zone calculations
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
tzlocal — pip install tzlocal · libregistry