Skip to main content

lesscode-database

CI Python 3.9+ License

Enterprise-grade database connection toolkit supporting 146 database dialects with a unified interface.

Features

  • Unified connection management — single API for relational, NoSQL, vector, graph, time-series, cloud data warehouses, and Chinese domestic databases
  • Connection pooling — automatic pool creation (sync and async) with configurable sizes
  • Async-first — full support for async/await where the driver allows it
  • Built-in ORM — lightweight SQL generation (SELECT, INSERT, UPDATE, DELETE, CREATE TABLE) with parameter binding
  • SQL injection prevention — parameterised conditions via helper functions (eq, in_list, between, like_, etc.)
  • Model generation — CLI tool to auto-generate ORM model files from existing database schemas

Quick Start

from lesscode_database.connection_info import ConnectionInfo
from lesscode_database.db_options import db_options
from lesscode_database.ds_helper import DsHelper

# 1. Configure connections
db_options.conn_list = [
    ConnectionInfo(
        dialect='mysql', name='mydb', host='127.0.0.1',
        port=3306, user='root', password='secret',
        db_name='test', enable=True,
    ),
]

# 2. Acquire a connection and execute SQL
with DsHelper('mydb').pool.dedicated_connection() as conn:
    with conn.cursor() as cursor:
        cursor.execute('SELECT 1')
        print(cursor.fetchone())

Installation

# Core package (no drivers)
pip install lesscode-database

# With specific driver groups
pip install "lesscode-database[mysql]"
pip install "lesscode-database[postgresql]"
pip install "lesscode-database[clickhouse]"
pip install "lesscode-database[mongo]"
pip install "lesscode-database[all]"   # everything

Documentation

Supported Databases (146 dialects)

Standard Databases

MySQL, MariaDB, PostgreSQL, ClickHouse, SQLite, MSSQL, Oracle

NoSQL Databases

MongoDB, Redis, Redis Cluster, Cassandra, ScyllaDB, Amazon Keyspaces, CouchDB, Couchbase, InfluxDB, DynamoDB, Timestream, DocumentDB, Memcached, ArangoDB, etcd, Firestore, Dgraph, SurrealDB

Graph Databases

Neo4j, Amazon Neptune, NebulaGraph, TigerGraph, JanusGraph, Azure Cosmos DB (Gremlin), GraphDB, Memgraph, OrientDB, Stardog, AllegroGraph, Fauna, Virtuoso, Galaxybase, TuGraph, StellarDB, Ultipa, gStore, PandaDB

Vector Databases

Milvus, Qdrant, Weaviate, Pinecone, OpenSearch, ChromaDB, PgVector, Redis Vector, LanceDB, Deep Lake, Vespa

Big Data / Cloud Data Warehouses

Hive, Spark Thrift, Trino, Presto, Impala, HBase, Kafka, Kudu, Flink SQL Gateway, Snowflake, Amazon Redshift, BigQuery, Databricks, Vertica, Teradata, Greenplum, MaxCompute, AnalyticDB, TCHouse, DWS, Azure Synapse Analytics, SQLAlchemy

Time-series / OLAP

TimescaleDB, CrateDB, Apache Druid, Apache Pinot, Prometheus, DuckDB

Enterprise Databases

SAP HANA, SAP ASE, IBM Informix, IBM Netezza, InterSystems Caché, IBM Db2, Firebird, SingleStore

Chinese MySQL-compatible Databases

TiDB, Doris, OceanBase, PolarDB, PolarDB-X, TDSQL, TDSQL-C, GoldenDB, GreatDB, GBase 8a, StarRocks, SelectDB, StoneDB, MatrixOne, Hubble

Chinese PostgreSQL-compatible Databases

KingbaseES, GBase 8c, openGauss, GaussDB, MogDB, AntDB, HighGo, UXDB, Vastbase, ShenTong, KaiwuDB, PgVector, KXData

Chinese Proprietary Databases

DaMeng (DM), ByConity, TDengine, YashanDB, SequoiaDB, XuguDB, GBase 8s, Kylin, CirroData, TimechoDB, DolphinDB, ArgoDB, Hippo

Chinese Vector Databases

Tencent Cloud VectorDB, VexDB, DingoDB, Vearch, VikingDB, Baidu VectorDB, TensorDB, Descartes, ArcVector

ORM Example

from lesscode_database.orm.orm_model import BaseModel
from lesscode_database.orm.orm_typing import Int, Varchar, eq
from lesscode_database.orm.orm_exec import Select, CreateTable

class User(BaseModel):
    __table_name__ = 'users'
    __bind_key__ = 'postgresql'
    id = Int('id', int, primary_key=True)
    name = Varchar('name', str, length=100)

# Generate DDL
ddl = CreateTable(User)._sql()
print(ddl)

# Build a query
sel = Select(User.id, User.name).select_from(User).where(eq(User.id, 1))
print(sel._sql())      # SELECT users.id,users.name FROM users WHERE users.id=%s
print(sel._params)     # [1]

See example/orm.py for more ORM examples.

Model Code Generation

# Generate model files from an existing MySQL database
model-gen --url "mysql+pymysql://user:pass@host:3306/db" --output ./models

# From PostgreSQL
model-gen --url "postgresql+psycopg2://user:pass@host:5432/db" --output ./models

# From SQLite
model-gen --url "sqlite+aiosqlite:///path/to/db.sqlite" --output ./models

# From ClickHouse
model-gen --url "clickhouse+clickhouse_driver://user:pass@host:9000/db" --output ./models

Development

make install-dev   # install with all extras
make check         # lint + format check + type check
make test          # run tests
make test-cov      # run tests with coverage

License

MIT

Metadata

Release files for lesscode-database 0.0.14

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

Source distribution (sdist)

Source distribution for lesscode-database 0.0.14
File Size Uploaded
lesscode_database-0.0.14.tar.gz 103.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lesscode-database 0.0.14
File Interpreter ABI Platform
lesscode_database-0.0.14-py3-none-any.whl Python 3 none any Details

Total release size: 248.2 kB

Release files / lesscode_database-0.0.14.tar.gz

Download URL lesscode_database-0.0.14.tar.gz
Size 103.8 kB
Tags Source
SHA-256 checksum
How to use checksums
58e506b621f6c0cdb075786e524cdf3d20d89783d3859d390cdfa039ae5d2cb1
BLAKE2b-256 checksum
How to use checksums
80aa64683cdf18c60718333768377ae9fc68cbcd889063b78ef86efff37805a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / lesscode_database-0.0.14-py3-none-any.whl

Download URL lesscode_database-0.0.14-py3-none-any.whl
Size 144.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5f55c92541b108a060e29febe4dbc870d30a6a12c3d6c3cf7902bed98883254
BLAKE2b-256 checksum
How to use checksums
661f3be9864661f8a2fba75a29fc656b231a508708d99efbdb77e2da71d6a44c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.0.14 This release

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.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