Enterprise-grade database connection toolkit supporting MySQL, PostgreSQL, ClickHouse, MongoDB, Redis, Elasticsearch, Neo4j, and more
Project description
lesscode-database
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
- Documentation Index — per-dialect docs for all 146 databases
- Connection Configuration
- Connection Pools
- ORM Usage
- Examples
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lesscode_database-0.0.14.tar.gz.
File metadata
- Download URL: lesscode_database-0.0.14.tar.gz
- Upload date:
- Size: 103.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58e506b621f6c0cdb075786e524cdf3d20d89783d3859d390cdfa039ae5d2cb1
|
|
| MD5 |
eea236ef5d37b8a41e4451050c603f2f
|
|
| BLAKE2b-256 |
80aa64683cdf18c60718333768377ae9fc68cbcd889063b78ef86efff37805a1
|
File details
Details for the file lesscode_database-0.0.14-py3-none-any.whl.
File metadata
- Download URL: lesscode_database-0.0.14-py3-none-any.whl
- Upload date:
- Size: 144.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5f55c92541b108a060e29febe4dbc870d30a6a12c3d6c3cf7902bed98883254
|
|
| MD5 |
c5e8a52f0a73dea6ad949bfd290da42f
|
|
| BLAKE2b-256 |
661f3be9864661f8a2fba75a29fc656b231a508708d99efbdb77e2da71d6a44c
|