Skip to main content

Heliclockter

PyPI License Python Versions

Timezone-aware datetimes for Python that just work.

heliclockter is a timezone-aware datetime library that ensures your timestamps are always timezone-aware. It's statically type checkable and runtime enforceable.

Installation

pip install heliclockter

Quick Start

from heliclockter import datetime_utc, datetime_local, datetime_tz

# UTC datetime
utc_now = datetime_utc.now()
# datetime_utc(2022, 11, 4, 15, 28, 10, 478176, tzinfo=zoneinfo.ZoneInfo(key='UTC'))

# Local timezone datetime  
local_now = datetime_local.now()

# Any timezone datetime
from zoneinfo import ZoneInfo
paris_tz = datetime_tz.now(tz=ZoneInfo("Europe/Paris"))

# Create a timestamp 2 hours in the future
future = datetime_utc.future(hours=2)

# Parse strings (naive timestamps assumed UTC)
parsed = datetime_utc.strptime('2022-11-04T15:49:29', '%Y-%m-%dT%H:%M:%S')

Why heliclockter?

Python's standard datetime allows "naive" datetimes without timezone info, leading to bugs when:

  • Mixing naive and aware datetimes (causes runtime TypeErrors)
  • Deploying across different timezones
  • Forgetting to add tzinfo when creating datetimes

heliclockter enforces timezone-aware datetimes at the type level, catching these issues before production.

Key Features

  • Always timezone-aware - No more naive datetime accidents
  • Type safe - Full typing support for better IDE experience
  • Zero dependencies - Lightweight, uses only standard library
  • Pydantic support - Automatic integration when Pydantic is installed
  • Python 3.10+ - Modern Python for modern applications

Examples

Timezone conversions

from heliclockter import datetime_utc, datetime_tz
from zoneinfo import ZoneInfo

# Start with UTC
utc_time = datetime_utc.now()

# To convert to different timezones, create custom classes
class datetime_tokyo(datetime_tz):
    assumed_timezone_for_timezone_naive_input = ZoneInfo('Asia/Tokyo')

class datetime_ny(datetime_tz):
    assumed_timezone_for_timezone_naive_input = ZoneInfo('America/New_York')

# Convert using from_datetime
tokyo_time = datetime_tokyo.from_datetime(utc_time)
ny_time = datetime_ny.from_datetime(utc_time)

Handling naive datetimes

from heliclockter import datetime_utc, datetime_tz
from datetime import datetime

# datetime_utc assumes UTC for naive inputs
naive_dt = datetime(2022, 11, 4, 15, 30, 0)
utc_dt = datetime_utc.from_datetime(naive_dt)  # OK - assumes UTC

# datetime_tz requires explicit timezone
try:
    tz_dt = datetime_tz.from_datetime(naive_dt)  # Raises error
except Exception as e:
    print(e)  # "Cannot create aware datetime from naive if no tz is assumed"

Custom timezone classes

from zoneinfo import ZoneInfo
from heliclockter import datetime_tz

class datetime_cet(datetime_tz):
    """Datetime guaranteed to be in CET timezone."""
    assumed_timezone_for_timezone_naive_input = ZoneInfo('CET')

# Parse naive timestamps as CET
aware_dt = datetime_cet.strptime('2022-11-04T15:49:29', '%Y-%m-%dT%H:%M:%S')

Type safety with mypy

from heliclockter import datetime_utc, datetime_local

def schedule_task(when: datetime_utc) -> None:
    """Schedule a task at a specific UTC time."""
    print(f"Task scheduled for {when.isoformat()}")

# Type checker ensures only UTC datetimes are passed
utc_time = datetime_utc.now()
schedule_task(utc_time)  # ✓ OK

local_time = datetime_local.now()  
schedule_task(local_time)  # ✗ Type error

API Overview

Core Classes

  • datetime_tz - Base class for timezone-aware datetimes
  • datetime_utc - Always UTC (naive inputs assumed UTC)
  • datetime_local - Always local timezone (naive inputs assumed local)

Key Methods

  • now() - Current time
  • from_datetime() - Convert from standard datetime
  • strptime() - Parse string to datetime
  • future()/past() - Create relative timestamps
  • astimezone() - Convert to other timezone

About the Name

heliclockter is a portmanteau of "clock" and "helicopter". Like a helicopter parent, it strictly supervises your datetime handling, ensuring you never make timezone mistakes.

Contributing

We welcome contributions! See CONTRIBUTING.md.

Python and Pydantic compatibility

The table below shows which Pydantic and Python versions are supported for which heliclockter version. Note that the latest version of heliclockter dropped support for Pydantic v1 code completely, meaning that you also can't use heliclockter in combination with the pydantic.v1 module in Pydantic v2.

heliclockter version Pydantic support Python support
1.0 v1 3.9, 3.10, 3.11, 3.12, 3.13
1.1, 1.2, 1.3 v1, v2 3.9, 3.10, 3.11, 3.12, 3.13
2.x v1, v2 3.10, 3.11, 3.12, 3.13
3.x v2 3.10, 3.11, 3.12, 3.13, 3.14

License

BSD 3-Clause License. See LICENSE.

Metadata

Release files for heliclockter 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for heliclockter 3.0.1
File Size Uploaded
heliclockter-3.0.1.tar.gz 19.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for heliclockter 3.0.1
File Interpreter ABI Platform
heliclockter-3.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 27.6 kB

Release files / heliclockter-3.0.1.tar.gz

Download URL heliclockter-3.0.1.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bedc66fe18548abc9088d0bb7c2bcd764f980607cb1954ac83f0e17b1d366c10
BLAKE2b-256 checksum
How to use checksums
1c3ff66932893ff052d7e3416b3af9084f9523dad3941ff166b3958f89477101
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / heliclockter-3.0.1-py3-none-any.whl

Download URL heliclockter-3.0.1-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b453481854a8d10c9f08b0a272bc757133054741f4ef0fcbb675135b95207ce8
BLAKE2b-256 checksum
How to use checksums
381e6fee94fcc46955b4e4447b72ab257fae66bcb2fbdbe54c7c67432ff95318
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

3.0.1 This release

2 release files

3.0.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page