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.1.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.1.tar.gz.
File metadata
- Download URL: chronotype-0.1.1.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 |
829cb04a7962d9604af9d0356dcb8d8886ed96c5ad51aa9885af5aed37ea9bec
|
|
| MD5 |
6e2b1cf1cfe0e8894cd87e9f01e39e21
|
|
| BLAKE2b-256 |
20ff98c91752fafe91cef2d2bb97fb2c646c3dbbfe1075e311f0ec5eb3c63fbf
|
File details
Details for the file chronotype-0.1.1-py3-none-any.whl.
File metadata
- Download URL: chronotype-0.1.1-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 |
7a65d8563081df81f78c4ab8efacd2f7bdff46f4ca1d92b44ff2ba9ffc0bee52
|
|
| MD5 |
77b03c88068134dfe9807f9c5dbbfcfc
|
|
| BLAKE2b-256 |
a25b48faf65c20d6fb3083e380de25c9ccc41b5ae529d76dd5e5a64a95427549
|