tzlocal

Detects the operating system's local timezone as a Python tzinfo object

Library
PyPI
v5.4.4
220 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
43 /100 Fair
Development Activity 16
Maintenance 0
Community 76
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
79 /100 Good
Architecture 78
Code Quality 80
Innovation 65
Learning Curve 92

tzlocal solves a small but consistently annoying problem: Python’s standard library has no reliable, cross-platform way to ask “what timezone is this machine set to?” tzlocal inspects /etc/timezone, /etc/localtime, environment variables, and systemd/dbus on Linux, NSTimeZone-equivalent system calls on macOS, and the Windows registry (via a maintained IANA-to-Windows timezone name mapping) to return a proper zoneinfo/pytz-compatible tzinfo object.

It’s a small, focused dependency pulled in transitively by much larger packages (APScheduler, various datetime and scheduling libraries) whenever they need to default to “the user’s local timezone” without asking the user to specify it explicitly.

What You Get

  • get_localzone() — a single function that returns the system’s local timezone as a zoneinfo.ZoneInfo (or pytz timezone if configured) object
  • Platform detection logic for Linux/Unix (/etc/timezone, /etc/localtime, systemd/dbus), macOS, and Windows
  • A maintained IANA <-> Windows timezone name mapping (windows_tz.py) kept in sync via update_windows_mappings.py, since Windows doesn’t use IANA tz names natively
  • get_localzone_name() for just the timezone name string when a full tzinfo object isn’t needed
  • Graceful fallback behavior when timezone detection is ambiguous or the environment is misconfigured (e.g. inside minimal Docker containers)

Common Use Cases

  • Defaulting a scheduling library (cron-like jobs, calendar apps) to the user’s local timezone when none is explicitly configured
  • Displaying timestamps to users in their own local time without asking them to select a timezone from a dropdown
  • Logging or auditing systems that need to record events in local time alongside UTC
  • CLI tools and desktop applications that need consistent, cross-platform timezone detection without shelling out to OS-specific commands

Under The Hood

Architecture - A thin dispatch layer in __init__.py (15 lines) selects between unix.py, win32.py at import time based on sys.platform, delegating all OS-specific detection logic to the platform module while sharing validation helpers in utils.py.

Tech Stack - Pure Python standard-library-only on Python 3.9+ (using zoneinfo from the stdlib), with pytz-deprecation-shim for backward compatibility with code still expecting pytz timezone objects; no compiled extensions.

Code Quality - Tests cover each platform’s detection path with mocked filesystem/registry state; windows_tz.py — a 736-line generated mapping table — is kept current via a dedicated update_windows_mappings.py script that pulls from Unicode CLDR data rather than being hand-maintained.

API Design - The entire library boils down to one function call, get_localzone(), that just works regardless of OS — there’s no configuration object or platform-conditional code required from the caller, which is exactly why so many other libraries pull it in as a dependency rather than reimplementing detection themselves.

Used by 5 apps in this directory

C++
68%
Apache 2.0

ClickHouse

Analytics · Data Engineering · Databases

50,116

Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.

View details
95
Repo Health
90
Technical
64
Dependency
Built with
C++ 68%
Python 14%
Updated 4 days ago
HTML
46%
LGPL-2.1

Horilla

ERP · Human Resources

1,437

Open-source HRMS covering recruitment, attendance, payroll, and biometrics in one self-hosted Django application.

View details
91
Repo Health
60
Technical
65
Dependency
Built with
HTML 46%
Python 38%
JavaScript 12%
Updated 4 days ago
Python
46%
Other

Redash

Analytics · Data Engineering

28,817

Redash lets anyone connect to 35+ SQL and NoSQL data sources, write a query in the browser, and turn the result into a shared dashboard — no separate BI suite required.

View details
92
Repo Health
74
Technical
60
Dependency
Built with
Python 46%
JavaScript 30%
TypeScript 17%
Updated 4 days ago
Python
94%
Apache 2.0

SWIRL

Data Engineering · Databases · Search

3,047

Federated AI search and RAG across 100+ enterprise sources—no data extraction, no vector database required.

View details
62
Repo Health
83
Technical
65
Dependency
Built with
Python 94%
Updated 6 days ago
C
76%
AGPL 3.0

TDengine

Databases

25,146

A high-performance, open-source time-series database built in C for IoT, connected vehicles, and industrial monitoring workloads, with built-in stream processing, caching, and data subscription.

View details
97
Repo Health
71
Technical
68
Dependency
Built with
C 76%
C++ 16%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers