django-simple-timeseries
Serializes small, simple timeseries to a database with Django. Provides the Timeseries class for manipulating timeseries, and the TimeseriesField custom field type for serializing.
Status: Experimental.
Table of Contents
Example
Define a TimeseriesField on a model:
from django.db import models
from django_simple_timeseries import TimeseriesField
class Appliance(models.Model):
name = models.CharField(max_length=64)
temperature = TimeseriesField(
resolution_seconds=60 * 60,
max_points=24,
help_text="Last 24 hours of temperature data",
)
You can then access Timeseries methods on it:
>>> a = Appliance(name='fridge')
>>> a.temperature.add(23.2)
>>> a.save()
>>> # Wait some time.
>>> a.temperature.add(26.5)
>>> a.save()
>>> print(list(a.temperature.iter_points()))
[
(datetime(2020, 1, 1, 2, 30, 0, tzinfo=<UTC>), 23.2),
(datetime(2020, 1, 2, 2, 30, 0, tzinfo=<UTC>), 26.5),
]
Requirements
This package is tested against the latest versions of:
- Python: 3.12, 3.13, 3.14
- Django: 4.2, 5.2, 6.0
- MySQL: 8.0
- PostgreSQL: 14
- SQLite: 3.9.0+
All database backends are tested with the latest versions of their drivers. SQLite is also tested on GitHub Actions' latest macOS virtual environment.
Installation
pip install django_simple_timeseries
How it works
Timeseries
The Timeseries class implements a simple vector-like timeseries. Timeseries data is always contiguous.
Internally, all timeseries instances have:
.start_time, adatetime.datetimecorresponding to the first data point;.data_points, the recorded data points (or y-values); and.resolution, a timedelta which describes the fixed interval between samples.
Samples are added by calling the add() method. The add() method ensures contiguousness with the following policy:
- If fewer than
resolutionseconds have elapsed since the most recent sample, the most recent sample is replaced. - If more than
resolutionseconds have elapsed since the last sample, the vector is extended by the appropriate number of samples (time_delta % resolution - 1), each which will be recorded as gaps with the valueNone. - In all cases, the vector is trimmed to no more than
max_pointssamples.
TimeseriesField
TimeseriesField is implemented as, and extends, a JSONField. The Timeseries methods .to_object() and .from_object() serialize a Timeseries instance to and from plain python objects, which the custom field type transparently implements.
Usage Notes
This module is experimental and hasn't been exhaustively tested. It is not intended for large timeseries. Use at your own risk!
API reference
Complete reference documentation for the public classes and methods, generated from the library's docstrings, lives in docs/api.md.
Maintainer notes
See docs/maintainer-notes.md for how releases are cut and published.
Changelog
See CHANGELOG.md.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 django_simple_timeseries-0.4.0.tar.gz.
File metadata
- Download URL: django_simple_timeseries-0.4.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2433acff8040f1f747476aae3d42e54845f972d128f11edbe5e61522f9e7c905
|
|
| MD5 |
b5aabe62cb1cd61fa5d536b5e835ab3d
|
|
| BLAKE2b-256 |
73a4ca343e9bf007200bd4ccb06f4ca2188ed293f1322d126d9a15a21a9c2f6d
|
Provenance
The following attestation bundles were made for django_simple_timeseries-0.4.0.tar.gz:
Publisher:
publish.yml on mik3y/django-simple-timeseries
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_simple_timeseries-0.4.0.tar.gz -
Subject digest:
2433acff8040f1f747476aae3d42e54845f972d128f11edbe5e61522f9e7c905 - Sigstore transparency entry: 2415009804
- Sigstore integration time:
-
Permalink:
mik3y/django-simple-timeseries@a160469eabb0d314d12a9d33552ec98aa60ae4c6 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/mik3y
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a160469eabb0d314d12a9d33552ec98aa60ae4c6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_simple_timeseries-0.4.0-py3-none-any.whl.
File metadata
- Download URL: django_simple_timeseries-0.4.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0a00ddeb90234b2dbd0358ffafd933425a726c16d9c9df84308bfdbaf88c77a
|
|
| MD5 |
6e4ba3b0ee88a7f2bc5b15854201993e
|
|
| BLAKE2b-256 |
58eb1127c925415843fc916d1d398b5cf76149772ee23066607f6e7455ba2d0f
|
Provenance
The following attestation bundles were made for django_simple_timeseries-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on mik3y/django-simple-timeseries
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_simple_timeseries-0.4.0-py3-none-any.whl -
Subject digest:
c0a00ddeb90234b2dbd0358ffafd933425a726c16d9c9df84308bfdbaf88c77a - Sigstore transparency entry: 2415009855
- Sigstore integration time:
-
Permalink:
mik3y/django-simple-timeseries@a160469eabb0d314d12a9d33552ec98aa60ae4c6 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/mik3y
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a160469eabb0d314d12a9d33552ec98aa60ae4c6 -
Trigger Event:
push
-
Statement type: