Skip to main content

Carbonic

A modern Python datetime library with fluent API, 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 ciso8601 integration 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"

Metadata

Release files for carbonic 1.0.2

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

Source distribution (sdist)

Source distribution for carbonic 1.0.2
File Size Uploaded
carbonic-1.0.2.tar.gz 73.9 kB Details

Built distribution (wheel)

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

Total release size: 121.3 kB

Release files / carbonic-1.0.2.tar.gz

Download URL carbonic-1.0.2.tar.gz
Size 73.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f16ac101dc38f4e1c132771d4e6fb90ff1f5d82c8f4beef3e9543d1f9d5037b2
BLAKE2b-256 checksum
How to use checksums
92d2ffb54ec0e2d1e3d541fa00212734a3c6503b5de7f807e2324656b4609f6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.19

Release files / carbonic-1.0.2-py3-none-any.whl

Download URL carbonic-1.0.2-py3-none-any.whl
Size 47.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99d22fd6aa853a082a8b56a29e628ec5eaa459c58a3bc2e017982f19da6f3fb0
BLAKE2b-256 checksum
How to use checksums
4ba941e77b5de1581219c8466c914fe06e0b5779e2ae9b27b12735f9f0ec5192
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.19

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.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