Skip to main content

TinyFlux is the tiny time series database optimized for your happiness 😎

TinyFlux is the time series version of TinyDB that is written in Python and has no external dependencies. It consistently writes atomically to file at over 6,000 writes per second and supports greater than 100 queries per second for time-based range queries on datasets up to 100,000 points. It's a perfect companion for small analytics workflows and apps, as well as at-home IOT data stores. TinyFlux has 100% test coverage, over 150,000 downloads, and no open issues.

Documentation Version Downloads Coverage Build Status

Installation

Install from PyPI:

pip install tinyflux

Quick Start

from datetime import datetime, timezone
from tinyflux import TinyFlux, Point

# Create database
db = TinyFlux('sensor_data.csv')

# Insert a data point
point = Point(
    time=datetime.now(timezone.utc),
    measurement='temperature', 
    tags={'sensor': 'living_room', 'unit': 'celsius'},
    fields={'value': 23.2}
)
db.insert(point)

# Query recent data
from tinyflux.queries import TimeQuery
recent_data = db.search(TimeQuery() >= datetime.now(timezone.utc).replace(hour=0))
print(f"Today's readings: {len(recent_data)}")

Why TinyFlux?

🚀 Simple: Clean, intuitive API inspired by TinyDB
📈 Fast: Optimized for time series workloads with automatic indexing
💾 Flexible: Memory or file-based storage with human-readable CSV format
🔍 Powerful: Rich query system with time-range, tag, and field filtering
🪶 Lightweight: Zero external dependencies, pure Python

Core Concepts

  • Point: A single time series record with timestamp, measurement, tags, and fields
  • Measurement: Logical grouping of related points (like a table)
  • Tags: Indexed metadata for grouping and filtering (strings only)
  • Fields: Actual time series values (numbers, strings, booleans)
  • Queries: Flexible filtering system for retrieving data

Performance

TinyFlux delivers high-performance time series operations across database sizes. Benchmarks conducted on macOS 15.4.1 with Intel i5 (6 cores), 32GB RAM, Python 3.13.5.

Key Performance Metrics

Database Size Writes (Memory) Writes (CSV) Range (Memory) Range (CSV) Lookup (Memory) Lookup (CSV)
ops/sec ops/sec QPS QPS QPS QPS
10K points 326,072 6,642 4,635 2,824 855 37
50K points 333,242 6,218 587 402 116 7
100K points 364,261 6,425 122 126 50 3

Query Types Explained:

  • Range Queries: Retrieve data within a time window (e.g., "all temperature readings from 9am-5pm"). This is the most common TSDB usage pattern.
  • Point Lookups: Find specific records by identifier (e.g., "sensor_001's latest reading"). Less common in typical time series workflows.

Key Insights:

  • ⚡ Write performance is constant regardless of database size (append-only architecture)
  • 🚀 Batch inserts achieve 10-12x speedup over individual inserts for CSV storage
  • 📊 Range queries (typical TSDB usage) perform excellently: 122-4,635 QPS (Memory), 126-2,824 QPS (CSV)
  • 💾 Time series queries scale well on both storage types, CSV even matches Memory at 100K points
  • 🗃️ Index scales efficiently: 35MB memory for 100K points with 0.9s rebuild time

See detailed performance analysis below for comprehensive benchmarks and visualizations.

Run your own benchmarks: python performance_tests/benchmark.py

Advanced Features

Batch Operations

# Efficient bulk inserts
points = [Point(...) for _ in range(1000)]
db.insert_multiple(points, batch_size=1000)  # 10-12x faster than individual inserts

Flexible Queries

from tinyflux.queries import FieldQuery, TagQuery, TimeQuery

# Range queries (most common for time series)
last_hour = db.search(TimeQuery() >= datetime.now(timezone.utc) - timedelta(hours=1))

# Tag filtering
sensor_data = db.search(TagQuery().sensor == 'living_room')

# Complex queries
hot_readings = db.search(
    (FieldQuery().temperature > 25) & 
    (TagQuery().location == 'bedroom')
)

Measurements (Like Tables)

# Work with specific measurements
temps = db.measurement('temperature')
temps.insert(point)
hot_days = temps.search(FieldQuery().value > 30)

Storage Options

CSV Storage (Default)

  • Human-readable format
  • Easy data import/export
  • Good for moderate datasets (<100K points)
  • Persistent across restarts

Memory Storage

  • Ultra-fast queries (50-855 QPS)
  • Perfect for high-frequency applications
  • All data in RAM
  • Use for temporary/cache scenarios
from tinyflux.storages import MemoryStorage
db = TinyFlux(storage=MemoryStorage)

Query Performance Scaling

Memory Storage: Fast queries with significant degradation at scale:

  • Point lookups: 855 → 50 QPS (10K → 100K points)
  • Range queries: 4,635 → 122 QPS (10K → 100K points)
  • Index performance degrades with dataset size despite 100% coverage

CSV Storage: Linear scan performance severely impacted by size:

  • Point lookups: 37 → 3 QPS (10K → 100K points)
  • All query types degrade significantly at 100K+ points (full file scans)
  • Range queries benefit from early termination: 2,824 → 126 QPS

Performance Visualizations

Write Performance Scaling

Write throughput remains consistent across database sizes for both storage types.

Read Performance Scaling

Query performance degradation analysis showing Memory vs CSV storage scaling.

Performance Analysis

Comprehensive performance insights including speedup ratios and key metrics.

Index Performance

TinyFlux automatic indexing provides:

  • Linear memory scaling: ~3-3.5 MB per 10K points (varies by storage type)
  • Rebuild performance: 0.23s (Memory) to 0.88s (CSV) for 100K points
  • 100% coverage: All points indexed for optimal query performance
  • Automatic maintenance: Index updates during batch operations

Optimization Recommendations

For Maximum Write Throughput:

  • Use Memory storage for fastest writes (326K-364K individual, 1.2M-1.4M batch writes/sec)
  • Prefer insert_multiple() for bulk operations (10-12x speedup for CSV)
  • Use batch sizes of 1,000 for optimal memory/performance balance

For Persistent Storage:

  • CSV storage provides human-readable persistence
  • Batch operations critical for CSV performance (10-12x speedup)
  • Consider write-heavy vs read-heavy workload patterns

For Query Performance:

  • Range queries (typical TSDB usage) perform well on both storage types (122-4,635 QPS)
  • Index-friendly query patterns (time ranges, specific tag lookups)
  • Consider data partitioning for very large datasets (>100K points)

TinyFlux Across the Internet

  • IoT Sensor Networks: Collect and analyze device telemetry
  • System Monitoring: Track server metrics and application performance
  • Financial Data: Store and query stock prices, trading volumes
  • Scientific Research: Log experimental measurements and observations
  • Web Analytics: Time-stamped user interaction data

Perfect for prototyping, edge computing, embedded systems, and applications where simplicity matters.

Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

License

MIT License. See LICENSE file for details.

Changelog

See CHANGELOG.rst for version history and updates.

Metadata

Release files for tinyflux 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tinyflux 1.2.0
File Size Uploaded
tinyflux-1.2.0.tar.gz 65.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tinyflux 1.2.0
File Interpreter ABI Platform
tinyflux-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 104.1 kB

Release files / tinyflux-1.2.0.tar.gz

Download URL tinyflux-1.2.0.tar.gz
Size 65.5 kB
Tags Source
SHA-256 checksum
How to use checksums
727a069ea8e4946c7c607005d7637b9ca48a4e47a7f7b7d5fb39b3b30a4e1dc3
BLAKE2b-256 checksum
How to use checksums
62d65e04766bead683b9fcb854eacf6aa5ea2a80acad921ddf47a0756460a5d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / tinyflux-1.2.0-py3-none-any.whl

Download URL tinyflux-1.2.0-py3-none-any.whl
Size 38.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8af3b1f95bedaafb791c7c3b9c3e6e941f05623a470676401d9e4c0f068bbc7a
BLAKE2b-256 checksum
How to use checksums
efb2c91d46913cb02f89283faa47782a12ca3316ed84fcdd62fd303343f7c2a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.6

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page