Skip to main content

Utils for SQL+Python - reliably work with SQL in Python apps

Project description

SQL+Python

A collection of utils to effortlessly and reliably interact between Python and your SQL database — purpose‑built for time‑series workflows. This package streamlines reading, writing, and maintaining SQL tables using familiar Python structures like pandas DataFrames, dictionaries, and other Python objects. It’s user-friendly, strict about data consistency, and tuned for time-series data pipelines. Intended for MariaDB/MySQL via SQLAlchemy - pre-configured docker environment included.

Design Principles

  • Predictable schemas: deterministic dtype mapping and optional auto-alter
  • Strong safeguards: explicit checks, clear assertions, and helpful errors
  • Pandas-friendly: minimal friction between DataFrame types and SQL
  • Maintainability: composable helpers for upload, fetch, and schema operations

Key Features

  • Focus on time-series data

    • Append-only patterns with optional “update latest” logic
    • Automatic handling of date/symbol index columns
    • Fast retrieval by symbol and date with optional indexing
    • Utilities to query by symbol(s), fetch latest dates, and union columns across tables
  • Works with your data structures

    • Upload pandas DataFrames with automatic dtype mapping
    • Store/retrieve dictionaries as rows
    • Persist arbitrary Python objects via pickling (e.g., models, configs)
    • Minimal boilerplate for table creation and updates
    • Smart dtype defaults for SQL schema generation
  • Safety and consistency checks

    • NaN/Inf coercion and validation for key columns
    • Duplicate/consistency guards when updating recent rows
    • Table introspection: add missing columns automatically (optional)
    • Environment validation and connection checks

Typical Use Cases

  • Maintain historical time-series data on a symbol-level (prices, indicators, metrics)
  • Incrementally update tables from pandas pipelines
  • Keep per-symbol metadata and snapshots
  • Store models or transforms in SQL as versioned pickles

Installation

  • Python: 3.12+
  • Installed packages: sqlalchemy, pandas etc.
  • Optional: Docker to use the docker compose environment that is set up to work wiht the utils - batteries included

Create/activate your virtualenv, then install your project’s dependencies as usual with pip inside the virtualenv. Run docker compose up in the project root to start the MariaDB container with the default environment variables.

Environment Variables

  • Standard DB credentials (e.g., user, password, host, port, database) loaded from your .env
  • A default setup for Docker is included
  • Built-in validation for host configuration; safe fallbacks if misconfigured

Quick Start

The main functions are listed below.

  • upload_df(): DataFrame uploads

    • Auto-creates tables with sensible column types (numeric as DOUBLE, categoricals as TEXT, datetimes as DATETIME) using create_table()
    • Optional table alteration to add newly appearing DataFrame columns
    • Optional enforcement of non-null date/symbol keys with configurable behavior
    • When uploading time-series data and using “update latest,” only the newest overlapping row(s) are replaced; older history remains intact
  • upload_dict(): Dictionary uploads

    • Keys become columns; can define a symbol column for idempotent updates
  • upload_object(): Object uploads

    • Serialize Python objects via pickle and store them in LONGBLOB columns
  • Retrieval helpers

    • get_symbol_data() or get_df_symbols_data(): Get time-series for a single symbol or multiple symbols
    • get_all_symbol_data(): Fetch all tables for a symbol in one go
    • get_existing_rows(): Inspect availability (tables exist, rows > 0), and compute the union of columns across tables

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

sqlpluspython-0.2.0.tar.gz (33.0 kB view details)

Uploaded Source

Built Distribution

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

sqlpluspython-0.2.0-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file sqlpluspython-0.2.0.tar.gz.

File metadata

  • Download URL: sqlpluspython-0.2.0.tar.gz
  • Upload date:
  • Size: 33.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sqlpluspython-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1e512cca02db4bf1cc21f9967f346f79cd575435c6b1c067a0e01af03fa8950a
MD5 e38642652873b29a4951f5af29ff81b6
BLAKE2b-256 80b5abe97d9432766b3427c5ebbe8e619bd88804f0239afeb814dc135f5bce86

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlpluspython-0.2.0.tar.gz:

Publisher: python-publish.yml on dennisdeh/SQLplusPython

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

File details

Details for the file sqlpluspython-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: sqlpluspython-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 36.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sqlpluspython-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a566c307c6eff71ed70c98fa01213a315a01c98dc91a061df80172518bb99b80
MD5 32f1a09bac78a2af58a7f12c12613379
BLAKE2b-256 e25853d39486acc7dc8c1aff48b679484dafb3caafafaa43f2e75a0f32b66967

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlpluspython-0.2.0-py3-none-any.whl:

Publisher: python-publish.yml on dennisdeh/SQLplusPython

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

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