This release is a pre-release and may not be stable for production use.
sql2func
Run SQL as a function!
Example
from dataclasses import dataclass
from typing import List
import mariadb
from sql2func import SqlContext, select
from sql2func.dbapi2 import Connection
@dataclass
class Foobar:
"""
Foobar data class
"""
fb_id: int
foo: str
bar: str
@select(statement='''
SELECT fb_id, foo, bar
FROM tbl_foobar
WHERE foo = {{ foo }}
''')
def select_foobars(foo: str) -> List[Foobar]:
pass
@update(statement='''
UPDATE tbl_foobar
SET bar = {{ bar }}
WHERE fb_id = {{ fb_id }}
''')
def update_foobar(fb_id: int, bar: str) -> int:
pass
def connect_to_db() -> Connection:
return mariadb.connect(
host='localhost',
user='db_user',
password='db_password',
database='db_name'
)
def _main():
with SqlContext(connector=connect_to_db):
# All SQLs in this context will be run via one DB connection.
# Run select.
for result in select_foobars(foo='foo'):
print(result)
# Run update.
update_foobar(fb_id=1, bar='blabla')
# DB connection will be closed after SqlContext exited.
if __name__ == '__main__':
_main()
Install
# Install release version
pip install sql2funcs
# Install develop version
pip install git+https://github.com/deadblue/sql2func.git@develop
Metadata
Release files for sql2func 0.0.1.dev3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sql2func-0.0.1.dev3.tar.gz | 8.1 kB | With provenance | Details for sql2func-0.0.1.dev3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sql2func-0.0.1.dev3-py3-none-any.whl | Python 3 | none | any | Details for sql2func-0.0.1.dev3-py3-none-any.whl |
Total release size: 20.6 kB
Release files / sql2func-0.0.1.dev3.tar.gz
| Download URL | sql2func-0.0.1.dev3.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a019df7517654e7420a8c83055c38b525214d1f597c6fd0e4beee5cc7474baa
|
|
BLAKE2b-256 checksum How to use checksums |
d3d6ae8ffb41fadef6f60222a2718aea1eed05b26baa9161346627c11cd6172f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 27, 2025.
Transparency logRelease files / sql2func-0.0.1.dev3-py3-none-any.whl
| Download URL | sql2func-0.0.1.dev3-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2a5a49811514e6b25a645705684811d42931701b2b611cc85096c5e5b4100b3
|
|
BLAKE2b-256 checksum How to use checksums |
5dc5d74d8ece2630131940fc010176145d977ed9f729b2ae083b1688da0278f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 27, 2025.
Transparency logSecurity for sql2func 0.0.1.dev3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sql2func-0.0.1.dev3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 27, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.