Metadata-Version: 2.4
Name: carbonic
Version: 1.0.0
Summary: A modern Python datetime library with fluent API and immutable design
Author-email: Marek Pilczuk <marek@mp76.pl>
Maintainer-email: Marek Pilczuk <marek@mp76.pl>
License-Expression: MIT
Project-URL: Repository, https://github.com/marepilc/carbonic
Project-URL: Issues, https://github.com/marepilc/carbonic/issues
Keywords: datetime,date,time,fluent,timezone,immutable
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: performance
Requires-Dist: ciso8601>=2.3.0; extra == "performance"
Provides-Extra: pydantic
Requires-Dist: pydantic>=2.0.0; extra == "pydantic"
Dynamic: license-file

# 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

```bash
# 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

```python
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"
