Python module for working with SQL Server and SQLite.
Project description
dapper_sqls
Python module for working with SQL Server and SQLite, providing synchronous and asynchronous access, typed models, query builders, and integrated HTTP clients.
Features
- Dapper (sync) and AsyncDapper — Execute queries and stored procedures with pyodbc (SQL Server) and configurable retry.
- Base models —
TableBaseModel,ViewBaseModel,StpBaseModelwith Pydantic, sensitive fields, and diff/comparison utilities. - QueryField — Typed construction of SELECT, JOIN, ORDER BY, HAVING, and query options.
- Builders —
QueryBuilder,StoredBuilder,StpBuilder,ViewBuilder(sync/async) and schema-based model generator. - Migration —
DataMigratorto migrate and compare data from SQL Server to SQLite (all tables or selected tables). - HTTP — Synchronous (
Request) and asynchronous (AioHttp) clients with models and decorators. - Local SQLite —
DataBaseInstall,BaseLocalDatabase,BaseAsyncLocalDatabase, safety decorators, and utilities. - Decorators —
func_validationandasync_func_validationfor input/output validation. - Result — Result wrappers (
Count,Fetchone,Fetchall,Insert,Send) and join/SQL helpers.
Requirements
- Python 3.8+
- For SQL Server: pyodbc (sync) and aioodbc (async)
- For SQLite: aiosqlite (async)
- Pydantic, aiohttp, requests, and other dependencies listed in
pyproject.toml
Installation
pip install dapper_sqls
Quick start
Dapper (SQL Server, synchronous)
from dapper_sqls import Dapper
dapper = Dapper(
server="localhost",
database="MyDatabase",
username="user",
password="password",
)
# Direct query
result = dapper.query().execute("SELECT 1 AS num")
rows = result.fetchall()
# Stored procedure
stored = dapper.stored().execute("usp_MyProcedure", param1="value")
AsyncDapper (SQL Server, asynchronous)
from dapper_sqls import AsyncDapper
dapper = AsyncDapper(server="...", database="...", username="...", password="...")
async def main():
result = await dapper.query().execute("SELECT * FROM Table")
rows = result.fetchall()
Models and builders
from dapper_sqls import TableBaseModel, ViewBaseModel, StpBaseModel, QueryField
class MyTable(TableBaseModel):
id: int
name: str
# Builders for queries, views, and stored procedures
from dapper_sqls import ModelBuilder, StpBuilder, ViewBuilder
Local SQLite
from dapper_sqls.sqlite import BaseLocalDatabase, DataBaseInstall, BaseTables
# Database setup/creation
installer = DataBaseInstall(
app_name="my_app",
tables=BaseTables,
path_local_database=".",
database_name="my_local",
database_folder_name="data",
)
# Using the synchronous base
db = installer.instance(BaseLocalDatabase)
Data migration (SQL Server -> SQLite)
from dapper_sqls import Dapper
from dapper_sqls.builders.generator.migration import DataMigrator
dapper = Dapper(server="localhost", database="MyDatabase", username="user", password="password")
migrator = DataMigrator(
dapper.config.connectionStringDataQuery,
sqlite_db_path="data/my_local.db",
sql_version=dapper.config.sql_version,
)
# Migrate all tables
result = migrator.migrate_all(clear_existing=False)
# Compare row counts between SQL Server and SQLite
stats = migrator.get_table_statistics()
Validation with decorators
from dapper_sqls import func_validation, async_func_validation
@func_validation
def my_function(x: int) -> str:
return str(x)
Project structure
dapper_sqls/
├── dapper/ # Synchronous Dapper and executors (Query, Stored)
├── async_dapper/ # AsyncDapper and async executors
├── models/ # Base (table, view, stp), query_field, result, connection, converter
├── builders/ # Query, Stored, Stp, View and model generator
├── http/ # Request, AioHttp, models and HTTP decorators
├── sqlite/ # Installer, BaseLocalDatabase, BaseAsyncLocalDatabase, decorators
├── config.py # Connection and retry configuration
├── decorators.py # func_validation, async_func_validation
└── utils.py # General utilities
Configuration
- SQL Server connection:
server,database,username,password; optionallysql_version,api_environment,default_attempts,default_wait_timeout.
License
Author
Samuel Semedo
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
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
dapper_sqls-1.0.1-py3-none-any.whl
(201.1 kB
view details)
File details
Details for the file dapper_sqls-1.0.1-py3-none-any.whl.
File metadata
- Download URL: dapper_sqls-1.0.1-py3-none-any.whl
- Upload date:
- Size: 201.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02dab9f0e0ee111791c1299cf46843c301135acbcf6e7b7de238c76ba155dcb9
|
|
| MD5 |
7c39789f24a11ad31f615f49d3cf3164
|
|
| BLAKE2b-256 |
b4ad3e1451f0ca0f54c321c9aafbd84da3bbafdaeaa01c6655d94e1c5f6bc063
|