Clever stuff with SQL in __doc__
Features
In-memory or file-backed database (Sqlite)
Post-process returned data
User definded functions
Example
Given this:
''' CREATE TABLE IF NOT EXISTS users (
userid INTEGER PRIMARY KEY,
username TEXT UNIQUE NOT NULL,
bcrypt BLOB NOT NULL
);
'''
from sqlfunc import sqlinit, sqludf, sqlfunc
__database__ = ':memory:' # default
@sqludf
def bcrypt_hash(password):
# call to library here
return b'$2b$12$.OjbRwRejxw92C89sA6JkOVrhmQzGsjoyCf1ofIN9hUNdHFufb3ty'
@sqludf
def bcrypt_verify(password, bcrypthash):
# call to library here
return True
@sqlfunc
def add_user(username, password):
''' INSERT OR IGNORE INTO $$$ (username, bcrypthash)
VALUES (:username, bcrypt_hash(:password));
'''
@sqlfunc(post=lambda x: bool(list(x)))
def login(username, password):
''' SELECT 1 FROM users
WHERE username=:username
AND bcrypt_verify(:password, bcrypt);
'''
sqlinit()
You can now do this:
>>> import example_users
>>> example_users.add_user('root', 'password123')
>>> example_users.login('root', 'secret')
False
>>> example_users.login('root', 'password123')
True
>>> example_users.list_users()
['root']
>>> 'bcrypt_verify' in dir(example_users) # helper functions are NOT exported
False
This library is MIT licensed.
Metadata
Release files for sqlfunc 0.1
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 |
|---|---|---|---|---|
| sqlfunc-0.1.tar.gz | 2.7 kB | Without provenance | Details for sqlfunc-0.1.tar.gz |
Release files / sqlfunc-0.1.tar.gz
| Download URL | sqlfunc-0.1.tar.gz |
|---|---|
| Size | 2.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35784a5b7831644a1f05b3a99bb839904bd133f9a2c0bc4b98ce8bfc00b7a476
|
|
BLAKE2b-256 checksum How to use checksums |
3e864272004a6e3de0cdaab8560baafa71cfffcc8922c3925e9d72e707334e81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for sqlfunc 0.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.