A modern Python datetime library inspired by PHP Carbon
Project description
Carbonic
A modern Python datetime library inspired by PHP Carbon, built with stdlib zoneinfo, dataclasses for immutability, and comprehensive localization support.
Carbonic provides an intuitive and fluent API for working with dates and times in Python, leveraging modern Python features for better type safety and performance.
Features
- 🚀 Fluent and immutable API - Built with dataclasses for type safety
- 🌍 Stdlib zoneinfo - Uses Python's built-in timezone support (no external dependencies)
- 🔒 Immutable by design - All operations return new instances
- 🌐 Full i18n support - English, Polish, and extensible locale system
- ⚡ High performance - Minimal overhead with stdlib components
- 🔧 Comprehensive formatting - Extensive date/time formatting options
- 📝 Human-readable differences - Localized relative time descriptions
- 🎯 Type-safe - Full type hints throughout
Installation
# Basic installation
pip install carbonic
# With performance optimizations (recommended)
pip install carbonic[performance]
Performance
Carbonic is designed for high performance with several optimizations:
- Fast ISO parsing: Optional
ciso8601integration for ~10x faster ISO 8601 datetime parsing - Memory efficiency: All classes use
__slots__for minimal memory overhead - Lazy evaluation: Expensive formatting operations (locale lookups, timezone formatting) are cached
- Stdlib only: Core functionality requires no external dependencies
Performance benchmark results:
- ISO parsing: 0.001ms per operation (with ciso8601)
- Formatting: 0.004ms per operation (with caching)
- Memory: 100% slot usage, no
__dict__overhead
Quick Start
from carbonic import DateTime, Duration
# Create and manipulate dates
now = DateTime.now()
tomorrow = now.add_days(1)
next_week = now.add(days=7)
# Parse ISO strings (fast with ciso8601)
dt = DateTime.parse("2024-12-25T15:30:00Z")
# Format with Carbon-style tokens
formatted = dt.format("F j, Y g:i A") # "December 25, 2024 3:30 PM"
# Localized formatting
polish = dt.format("F j, Y", locale="pl") # "grudzień 25, 2024"
# Duration calculations
duration = DateTime.now() - DateTime(2024, 1, 1)
print(duration.humanize()) # "11 months 3 weeks 2 days"
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file carbonic-0.2.0.tar.gz.
File metadata
- Download URL: carbonic-0.2.0.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77b60ef5efcb07615399e4bafe7eeeff4e938c3a40e154a09f22cd8ae431c3c5
|
|
| MD5 |
852cb61760368ec5970be35c91c4885e
|
|
| BLAKE2b-256 |
085ffced10f18a8dd8fece6d8125dfe7e6ae83145b197d8eff2bb2ccefc5d4c4
|
File details
Details for the file carbonic-0.2.0-py3-none-any.whl.
File metadata
- Download URL: carbonic-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f1ce5d04c05b3f0c547f945f3f0b05bac37d992733d3a4dc341fd7f6a89eb33
|
|
| MD5 |
20304c8943765ba36fc09e401af56f04
|
|
| BLAKE2b-256 |
73816eeb446726676f40cb26548fbb291f8649fd5ac11cfc2248c4aa4c73b226
|