Install & Compatibility
Where this runs
tested against v1.1.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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.002s · 17.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.002s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
truncate
✓ from datetime_truncate import truncate
✗ from datetime import truncate
datetime_truncate is a separate package, not part of stdlib.
Truncates to 'year', 'month', 'day', 'hour', 'minute', or 'second'. Returns a new datetime object.
from datetime import datetime
from datetime_truncate import truncate
dt = datetime(2025, 4, 15, 10, 30, 45, 123456)
truncated = truncate(dt, 'hour')
print(truncated) # 2025-04-15 10:00:00
Errors
Common errors & fixes
ImportError: cannot import name 'truncate_to' from 'datetime_truncate'
The function was renamed from truncate_to to truncate in version 1.1.0.
fixInstall latest version: pip install datetime-truncate --upgrade. Then use from datetime_truncate import truncate.
AttributeError: 'datetime.datetime' object has no attribute 'truncate'
datetime_truncate does not monkey-patch datetime; it provides a standalone function.
fixImport and call truncate() from datetime_truncate, not as a method on a datetime object.
ValueError: invalid level: 'weeks'
The library does not support truncation to weeks; only year, month, day, hour, minute, second.
fixUse 'day' or 'hour' and adjust manually.
Upgrade
Version history
1.1.1latest on PyPI · released Aug 6, 2020
Audit
Dependencies
No dependency data recorded yet.