Skip to main content

A database system built on top of smol-format for efficient storage and querying of structured data with exact rational number support

Project description

smol-db

A database system built on top of smol-format for efficient storage and querying of structured data with exact rational number support.

Overview

smol-db is a Python library that provides a database-like interface for storing and querying structured data, with a particular focus on preserving exact rational numbers of arbitrary size. It builds on top of smol-format to provide efficient storage while adding database features like indexing and querying.

Key features:

  • Exact preservation of rational numbers (no precision loss)
  • Efficient compression with Zstandard
  • Simple table-based data model
  • Indexing for fast lookups
  • Streaming support for large datasets
  • Simple API for database operations
  • Metadata tracking
  • Type preservation

Installation

pip install smol-db

Quick Start

from smol_db import SmolDB, DBConfig

# Initialize database
db = SmolDB(
    "my_database",
    config=DBConfig(
        compression_level=3,  # Zstandard compression level (1-22)
        cache_size=1000      # Number of rows to cache
    )
)

# Create a table
points_table = db.create_table("points", {
    "x": "rational",
    "y": "rational",
    "curve_id": "string"
})

# Create an index
points_table.create_index(["curve_id"])

# Insert data
points_table.insert({
    "x": "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679/10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "y": "271828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642/100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "curve_id": "E1"
})

# Query data
for point in points_table.select({"curve_id": "E1"}):
    print(f"Point: ({point['x']}, {point['y']})")

Documentation

Features

Exact Number Preservation

smol-db preserves rational numbers exactly as strings, without any loss of precision:

  • No floating-point approximations
  • Maintains numerator/denominator format
  • Supports arbitrarily large numbers
  • Perfect for mathematical applications

Efficient Storage

Data is stored using smol-format, which provides:

  • High compression ratios
  • Fast compression and decompression
  • Configurable compression levels
  • Excellent performance on text data

Database Features

smol-db adds database functionality:

  • Table-based data model
  • Indexing for fast lookups
  • Simple query interface
  • Type validation
  • Metadata tracking

Streaming Support

For large datasets, smol-db provides streaming capabilities:

  • Process data in chunks
  • Memory-efficient operations
  • Background processing
  • Progress tracking

Use Cases

smol-db is particularly useful for:

  • Scientific computing with exact rational arithmetic
  • Number theory research
  • Cryptography applications
  • Any application requiring exact rational number preservation
  • General structured data storage

Examples

Check out the examples directory for more detailed examples:

  • basic_usage.py: Basic database operations
  • indexing.py: Working with indexes
  • streaming.py: Handling large datasets

Performance

smol-db achieves good performance while maintaining exact precision:

  • Typical compression ratios: 2-5x for rational number data
  • Fast indexing for lookups
  • Efficient streaming for large datasets

See the Performance Guide for detailed benchmarks and optimization tips.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Security

Please report any security vulnerabilities to small.joshua@gmail.com. See our Security Policy for more details.

Code of Conduct

Please read our Code of Conduct to keep our community approachable and respectable.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smol_db-0.1.0.tar.gz (44.8 kB view details)

Uploaded Source

Built Distribution

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

smol_db-0.1.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file smol_db-0.1.0.tar.gz.

File metadata

  • Download URL: smol_db-0.1.0.tar.gz
  • Upload date:
  • Size: 44.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for smol_db-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4b09ae26b660ea5b85c4c8a89f452a03a655426c72beadb5e7a163ee632377d1
MD5 3189931d327fc54037c56abdc284b2cf
BLAKE2b-256 4c6a6e3fc8cf1922d44e70cc8a1f15d4145e856eb751ab8aa610f7449161fb51

See more details on using hashes here.

File details

Details for the file smol_db-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: smol_db-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for smol_db-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 decea41c1a1d79428d8bd59e747317757915a0a760c7d422f1c8bde13d6cf5e6
MD5 459bb1dad217ff571839b9d6fa8f2b8a
BLAKE2b-256 81a581d6e45b992db745178c87c8ca334bc2994ba583d246128ccd7980561eb8

See more details on using hashes here.

Supported by

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