Skip to main content

A modern Python datetime library with fluent API and immutable design

Project description

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"

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

carbonic-1.0.0.tar.gz (69.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

carbonic-1.0.0-py3-none-any.whl (45.0 kB view details)

Uploaded Python 3

File details

Details for the file carbonic-1.0.0.tar.gz.

File metadata

  • Download URL: carbonic-1.0.0.tar.gz
  • Upload date:
  • Size: 69.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.19

File hashes

Hashes for carbonic-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0dd50a0398b21034e2ccfcdc65ee138952965d7cad45659592516d9d2117b325
MD5 e52a37a4e0e2504a7874e7569d23e1fa
BLAKE2b-256 1042cfb616b6b230cfcdc04489121a1dca7eca69dbb0f1596efd35c568b88c27

See more details on using hashes here.

File details

Details for the file carbonic-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: carbonic-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 45.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.19

File hashes

Hashes for carbonic-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 389529910d6e9cc4c34adc3c86a8f2782d3841fc015aa3f4cdb9d2595a99ab1c
MD5 bad1851b51ee0fbfada2b0c0da7bc7f4
BLAKE2b-256 bbe594847759d20965654f5ed09529647f3ece695df2ed46f5fbfe6fce241699

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page