AnySQL
Lightweight, Thread-Safe, Version-Agnostic, SQL Client Implementation
inspired by Databases
Features
- Lightweight - no use of sqlalchemy or other massive frameworks
- ThreadSafe - implements threadsafe features for fearless concurrent usage
- Flexible - acts as a standard frontend for a wide variety of SQL backends
- Powerful - simple API design with powerful utilities and quality-of-life features
Installation
$ pip install anysql
$ pip install anysql[mysql]
$ pip install anysql[postgres]
Security
It should be noted that anysql implements its own query parameterization to
allow for greater API flexibility and performance, rather than rely on
individual sql backends or relying on massive frameworks like sqlalchemy to
handle query generation.
The existing parameterization has been thoroughly tested with
sqlmap, the world standard of
sql pentesting-tools, to prevent and detect any possible sql-injection
vulnerabilities.
The test-suite used is publically available within the source-code repo
within the tests
folder.
Example
from anysql import Database
database = Database('sqlite://:memory:')
database.connect()
query = """CREATE TABLE HighScores (id INTEGER PRIMARY KEY, name VARCHAR(100), score INTEGER)"""
database.execute(query=query)
query = "INSERT INTO HighScores(name, score) VALUES (:name, :score)"
values = [
{"name": "Daisy", "score": 92},
{"name": "Neil", "score": 87},
{"name": "Carol", "score": 43},
]
database.execute_many(query=query, values=values)
query = "SELECT * FROM HighScores"
rows = database.fetch_all(query=query)
print('High Scores:', rows)