Skip to main content

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.

PyPI version PyPI Supported Python Versions Test status

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, a datetime.datetime corresponding 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 resolution seconds have elapsed since the most recent sample, the most recent sample is replaced.
  • If more than resolution seconds 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 value None.
  • In all cases, the vector is trimmed to no more than max_points samples.

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

django_simple_timeseries-0.4.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

django_simple_timeseries-0.4.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

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

Hashes for django_simple_timeseries-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2433acff8040f1f747476aae3d42e54845f972d128f11edbe5e61522f9e7c905
MD5 b5aabe62cb1cd61fa5d536b5e835ab3d
BLAKE2b-256 73a4ca343e9bf007200bd4ccb06f4ca2188ed293f1322d126d9a15a21a9c2f6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_simple_timeseries-0.4.0.tar.gz:

Publisher: publish.yml on mik3y/django-simple-timeseries

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_simple_timeseries-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_simple_timeseries-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0a00ddeb90234b2dbd0358ffafd933425a726c16d9c9df84308bfdbaf88c77a
MD5 6e4ba3b0ee88a7f2bc5b15854201993e
BLAKE2b-256 58eb1127c925415843fc916d1d398b5cf76149772ee23066607f6e7455ba2d0f

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

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