Temporal-native data types where every value carries its full history
Project description
Chronotype
Temporal-native data types for Python. Every value inherently carries its full history.
Installation
pip install chronotype
Quick Start
from datetime import date, datetime
from chronotype import TemporalInt, TemporalFloat, TemporalString
# Create a temporal integer that tracks salary over time
salary = TemporalInt()
salary[date(2020, 1, 1)] = 50000
salary[date(2022, 6, 1)] = 65000
salary[date(2024, 1, 1)] = 80000
# Query at specific points in time
print(salary.at(date(2021, 3, 15))) # 50000
print(salary.at(date(2023, 1, 1))) # 65000
# Get the current (latest) value
print(salary.current()) # 80000
# Analyze over time ranges
query = salary.between(date(2020, 1, 1), date(2024, 1, 1))
print(query.average()) # Weighted average by duration
print(query.min()) # 50000
print(query.max()) # 80000
# Interpolation for numeric types
temp = TemporalFloat(interpolate=True)
temp[datetime(2024, 1, 1, 0, 0)] = 20.0
temp[datetime(2024, 1, 1, 12, 0)] = 25.0
print(temp.at(datetime(2024, 1, 1, 6, 0))) # 22.5 (interpolated)
Features
- Temporal Primitives:
TemporalInt,TemporalFloat,TemporalString,TemporalBool - Temporal Containers:
TemporalList,TemporalDict,TemporalSet - Generic Wrapper:
Temporal[T]for any type - Time Queries:
.at(),.between(),.current(),.first() - Aggregations:
.average(),.min(),.max(),.sum(),.count() - Interpolation: Linear interpolation for numeric types
- History:
.history(),.changes(),.rollback() - Arithmetic: Full operator support for numeric temporals
- Serialization: JSON and pickle support
Documentation
Creating Temporal Values
from chronotype import Temporal, TemporalInt
# With initial value (uses current time)
count = TemporalInt(initial=0)
# Empty, to be populated
score = TemporalInt()
# Generic temporal for custom types
from dataclasses import dataclass
@dataclass
class User:
name: str
active: bool
user = Temporal[User]()
user[datetime.now()] = User("Alice", True)
Time Range Queries
query = salary.between(date(2020, 1, 1), date(2023, 12, 31))
# Aggregations (weighted by duration)
query.average()
query.sum()
query.min()
query.max()
query.count()
# Get all entries
query.entries() # List of (timestamp, value) tuples
query.values() # List of values only
query.timestamps() # List of timestamps only
History Operations
# Full history
for timestamp, value in salary.history():
print(f"{timestamp}: {value}")
# Detect changes
for timestamp, old_val, new_val in salary.changes():
print(f"{timestamp}: {old_val} -> {new_val}")
# Rollback to previous state
salary.rollback() # Remove last entry
salary.rollback(to=date(2022, 1, 1)) # Remove all entries after date
Arithmetic Operations
a = TemporalInt(initial=10)
b = TemporalInt(initial=5)
# Operations create new temporals with aligned timestamps
c = a + b # TemporalInt
c = a - b
c = a * b
c = a / b # Returns TemporalFloat
c = a // b
c = a % b
c = a ** b
# Comparison creates TemporalBool
is_greater = a > b
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
chronotype-0.1.0.tar.gz
(17.6 kB
view details)
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 chronotype-0.1.0.tar.gz.
File metadata
- Download URL: chronotype-0.1.0.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7696ee89b29eae32e813e1abff8bd3c17cc430d41c0b62150323511c96acfe52
|
|
| MD5 |
37516930278d13b6d55b898afa694bff
|
|
| BLAKE2b-256 |
e7bd957936041fb4d98a79a4850db57da1f46a296baf2a786bc27a3c71f63e5e
|
File details
Details for the file chronotype-0.1.0-py3-none-any.whl.
File metadata
- Download URL: chronotype-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a53089b6394ffe82984a318279d2fa77ae924a89caafab3a6fd4c7848c31bab
|
|
| MD5 |
3714197464517383914fd52450542411
|
|
| BLAKE2b-256 |
bc7ce8b4d5230428185b402cc79f0d587ff62c1043c44be458d875d964ba408e
|