Skip to main content

explicit-sql

A human mind friendly SQL generator for DuckDB.

Overview

I genuinely do not like ORMs because of the Object–relational impedance mismatch. While we have many good ORMs that can speed up development of POCs and MVPs drastically, this project aims at a simpler idea: implement a human mind friendly and type-safe SQL generator for all basic operations:

  • CREATE TABLE
  • DROP TABLE
  • INSERT INTO
  • SELECT FROM
  • UPDATE
  • DELETE
  • And more...

I found myself developing this when working on simple side-projects using DuckDB and realized there was no interface to generate SQL queries from TypedDict definitions.

Philosophy

The goal is to stay as close to "raw" Python as possible. For table schemas, I chose TypedDict, and besides that have only two classes:

  1. TableConfig - for configuration settings
  2. ExplicitTable - a container class for both the TypedDict definition and config

This minimalist approach should be enough to achieve a useful, type-safe SQL generator without the complexity of ORMs.

Requirements

  • Python 3.10+

Installation

pip install explicit-sql

Quick Example

from explicit_sql import (
    TableDefinition,
    TableConfig,
    ExplicitTable,
    create_table_sql,
    insert_sql,
    select_sql
)

# Define your table schema
class UsersTable(TableDefinition):
    id: int
    name: str
    is_active: bool | None

users_config = TableConfig(
    name="users",
    schema="public",
    primary_key_name="id",
    primary_key_type=int,
)

users_table = ExplicitTable(
    config=users_config,
    table_definition=UsersTable
)

create_table_sql = create_table_sql(users_table)
print(create_table_sql)

insert_payload: UsersTable = {
    "amount": 500,
    "name": "John Doe",
    "is_active": True,
}
print(insert_sql(users_table, insert_payload))


print(
    select_sql(
        users_table,
        select_columns=["name", "amount"],
        where_values={"is_active": True},
        order_by=["amount"],
        limit=10,
    )
)

# Select all columns
print(select_sql(users_table, limit=10))

Roadmap

See the milestone plan for the development roadmap.

License

MIT

Metadata

Release files for explicit-sql 0.0.5

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

Source distribution (sdist)

Source distribution for explicit-sql 0.0.5
File Size Uploaded Provenance Actions
explicit_sql-0.0.5.tar.gz 12.2 kB Without provenance Details for explicit_sql-0.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for explicit-sql 0.0.5
File Interpreter ABI Platform Actions
explicit_sql-0.0.5-py3-none-any.whl Python 3 none any Details for explicit_sql-0.0.5-py3-none-any.whl

Total release size: 19.9 kB

Release files / explicit_sql-0.0.5.tar.gz

Download URL explicit_sql-0.0.5.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
462d3fef3395475e537466c27bd5b8e454343a18627e120eb2e3a542abfb4285
BLAKE2b-256 checksum
How to use checksums
ac38b850bc843449a661a92d21c8777701c1c2627567784ea37ee366a92ec2a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.6

Release files / explicit_sql-0.0.5-py3-none-any.whl

Download URL explicit_sql-0.0.5-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e953c28d759e569cd38ce456518d2309d1167b16338877cd533debebbcc3b987
BLAKE2b-256 checksum
How to use checksums
0bf5bd0de84154e89d56fcac6d3e7726e9deeee65266cf8948f79244d005ce67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.6

Security for explicit-sql 0.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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