Thin wrapper on top of SQL that enables you write SQL code in python easily
Project description
Supersql Library
There are many great database tools for python (i.e. databases, SQLAlchemy, PeeWee etc.) - but there is no Python tool for databases.
In addition you might have come to the same realisation and thinking the following:
-
But we don't want to use an ORM
-
Why can't we get a low level pythonic, powerful SQL api with with semantic interaction primitives
-
Async and Sync support should be supported
Supersql checks all those boxes and more. It is a python superset of SQL - allowing you leverage the full power of python to write advanced SQL queries.
Tutorial: Open Documentation
Requirements: Python 3.6+
NOTE: Still Very Much In Development
SELECT * FROM customers ORDER BY last_name DESC LIMIT 5
# query.SELECT('*') is the same as query.SELECT() or query.SELECT(customers)
query.SELECT().FROM(customers).ORDER_BY(last_name = -1).LIMIT(5)
Why?
Let's be honest:
-
Writing sql templates using string formatting is really painful.
-
Sometimes an ORM is not what you need, and whilst the new
f strings
in python solve a lot of problems, complex SQL templating is not of them. -
Supersql makes it super simple to connect to and start querying a database in python.
Let the code do the explanation:
from supersql import Query
query = Query('postgres://user:password@hostname:5432/database')
# Without table schema discovery/reflection i.e. using strings -- NOT OPTIMAL
results = query.SELECT(
'first_name', 'last_name', 'email'
).FROM(
'employees'
).WHERE(email = 'someone@example.com').execute()
for result in results:
print(result)
# reflect table schema and fields into a python object for easy querying
emps = query.database.table('employees')
records = query.SELECT(
emps.first_name, emps.last_name, emps.email
).FROM(
emps
).WHERE(emps.email == 'someone@example.com').execute()
What about support for Code First flows? Also supported using Table objects
from supersql import Table, Varchar, Date, Smallint
class Employee(Table):
"""
SuperSQL is not an ORM. Table only helps you avoid magic
literals in your code. SuperSQL is not an ORM
"""
__pk__ = ('email', 'identifier')
identifier = Varchar()
email = Varchar(required=True, unique=None, length=25)
age = Smallint()
first_name = String(required=True)
last_name = String(25)
created_on = Date()
# Now lets try again
emp = Employee()
results = query.SELECT(
emp.first_name, emp.last_name, emp.email
).FROM(emp).WHERE(
emp.email == 'someone@example.com'
).execute()
Note
Supersql is not an ORM so there is no magic Table.save() Table.find() features nor will they ever be supported.
The Table
class is provided only to help with magic literal elimination from your codebase i.e. a query helper and nothing more.
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
File details
Details for the file supersql-2023.5.11.tar.gz
.
File metadata
- Download URL: supersql-2023.5.11.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.11.3 Darwin/22.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66f7d9a1e4daf9c0a4b73d218b62653cd46c316bb82e3b2d3b85cc6b7be4f454 |
|
MD5 | b61c86cb7a7e1b7fd3704b924b233641 |
|
BLAKE2b-256 | 0c1efc6913bc65edcc19949cbc5610d3bd51500f8410ba6bb7ee4826a26204cd |
File details
Details for the file supersql-2023.5.11-py3-none-any.whl
.
File metadata
- Download URL: supersql-2023.5.11-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.11.3 Darwin/22.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25bbcd61236d3a3ddfc3527efe85b51920d30916b742154d15d1edaae0c3c5a2 |
|
MD5 | 6796c2ce908ccf297e3e76a3683f9732 |
|
BLAKE2b-256 | eeb32907cf45a3a79dc80757eb57986fc6b23f4d8bfcc854840ba3039c81de79 |