Skip to main content

A high-density data storage system for efficient encoding and decoding of structured data, with special support for large rational numbers

Project description

smol-format

A high-density data storage system for efficient encoding and decoding of structured data, with special support for large rational numbers.

Overview

smol-format is a Python library that provides efficient storage and retrieval of structured data, with a particular focus on preserving exact rational numbers of arbitrary size. It combines JSON encoding for data preservation with Zstandard compression to achieve high data density while maintaining exact precision.

Key features:

  • Exact preservation of rational numbers (no precision loss)
  • Efficient compression with Zstandard
  • Simple JSON-based encoding
  • Streaming support for large datasets
  • Simple API for encoding/decoding
  • Metadata tracking
  • Type preservation

Installation

pip install smol-format

Quick Start

from smol_format import DenseStorage, StorageConfig

# Initialize storage
storage = DenseStorage(
    config=StorageConfig(
        compression_level=3,  # Zstandard compression level (1-22)
        encoding="json"       # Use JSON encoding for data preservation
    )
)

# Example data with large rational numbers
data = {
    "numbers": [1, 2, 3, 4, 5],
    "rationals": [
        "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679/10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "271828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642/100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
    ]
}

# Encode data
encoded = storage.encode(data)

# Decode data
decoded = storage.decode(encoded)

# Get metadata
metadata = storage.get_metadata(data)
print(metadata)

Documentation

Features

Exact Number Preservation

smol-format 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 Compression

Data is compressed using Zstandard, which offers:

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

Streaming Support

For large datasets, smol-format provides streaming capabilities:

# Stream encode
for chunk in data_iterator:
    encoded_chunk = storage.encode(chunk)
    process_encoded_chunk(encoded_chunk)

# Stream decode
for chunk in encoded_chunks:
    decoded_chunk = storage.decode(chunk)
    process_decoded_chunk(decoded_chunk)

Metadata Management

Each dataset includes metadata:

  • Number of rows
  • Column information
  • Data types (with special handling for rationals)
  • Creation timestamp

Use Cases

smol-format 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:

  • rational_numbers.py: Working with large rational numbers
  • streaming.py: Handling large datasets with streaming
  • scientific_data.py: Scientific computing examples

Performance

smol-format achieves good compression ratios while maintaining exact precision:

  • Typical compression ratios: 2-5x for rational number data
  • Fast encoding/decoding through JSON
  • 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_format-0.1.2.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

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

smol_format-0.1.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file smol_format-0.1.2.tar.gz.

File metadata

  • Download URL: smol_format-0.1.2.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for smol_format-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5ac9c4ffe1f5954a68af0422f10c8979b55254f635851f58d3ea21bf3747077c
MD5 37e89217ba5af99b0dd510bb4076adc2
BLAKE2b-256 15f3d568a5e1749abcc6bd736ba5b222aec302b1602d2f60bc6e0ae42769a2a7

See more details on using hashes here.

File details

Details for the file smol_format-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: smol_format-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for smol_format-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b1a698ccaed1c9a447eef4e297d4d39086821c9a7c92f35c30869da19d658e7e
MD5 8fba89d9e6e8e102b0885a612cbced33
BLAKE2b-256 7a535410fa20fd717a4599c961ad1bae1dbfc46611286ee61d81c5174e0df90a

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