Privex's Python Database Library
+===================================================+
| © 2019 Privex Inc. |
| https://www.privex.io |
+===================================================+
| |
| Privex's Python Database Library |
| License: X11 / MIT |
| |
| Originally Developed by Privex Inc. |
| Core Developer(s): |
| |
| (+) Chris (@someguy123) [Privex] |
| |
+===================================================+
Privex's Python Database Library - Database wrappers, query builders, and other useful DB-related classes/functions
Copyright (c) 2019 Privex Inc. ( https://www.privex.io )
README under construction.
Install with pip
We recommend at least Python 3.6 - we cannot guarantee compatibility with older versions.
pip3 install privex-db
Basic Usage
Basic usage with SqliteWrapper and SqliteBuilder (db.builder())
from os.path import expanduser
from privex.db import SqliteWrapper
# Open or create the database file ~/.my_app/my_app.db
db = SqliteWrapper(expanduser("~/.my_app/my_app.db"))
# Create the table 'items' and insert some items
db.action("CREATE TABLE items (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);")
db.action("INSERT INTO items (name) VALUES (?);", ["Cardboard Box"])
db.action("INSERT INTO items (name) VALUES (?);", ["Orange"])
db.action("INSERT INTO items (name) VALUES (?);", ["Banana"])
db.action("INSERT INTO items (name) VALUES (?);", ["Stack of Paper"])
item = db.fetchone("SELECT * FROM items WHERE name = ?", ['Orange'])
print(item.id, '-', item.name)
# Output: 2 - Orange
q = db.builder('items')
# Privex QueryBuilder's support chaining similar to Django's ORM
q.select('id', 'name') \ # SELECT id, name FROM items
.where('name', 'Orange') \ # WHERE name = 'Orange'
.where_or('name', 'Banana') \ # OR name = 'Banana'
.order('name', 'id') # ORDER BY name, id DESC
# You can either iterate directly over the query builder object
for row in q:
print(f"ID: {row.id} Name: {row.name}")
# Output:
# ID: 3 Name: Banana
# ID: 2 Name: Orange
# Or you can use .fetch / .all to grab a single row, or all rows as a list
item = db.builder('items').where('name', 'Orange').fetch()
# {'id': 2, 'name': 'Orange'}
items = db.builder('items').all()
# [ {'id': 1, 'name': 'Cardboard Box'}, {'id': 2, 'name': 'Orange'}, ... ]
Documentation
Full documentation for this project is available above (click the Read The Docs image), including:
- How to install the application and it's dependencies
- How to use the various functions and classes
- General documentation of the modules and classes for contributors
To build the documentation:
pip3 install pipenv
git clone https://github.com/Privex/python-db
cd python-db/docs
pipenv install -d
# It's recommended to run make clean to ensure old HTML files are removed
# `make html` generates the .html and static files in docs/build for production
make clean && make html
# After the files are built, you can live develop the docs using `make live`
# then browse to http://127.0.0.1:8100/
# If you have issues with content not showing up correctly, try make clean && make html
# then run make live again.
make live
Unit Tests
To run the unit tests, clone the project and make a .env file containing details for a PostgreSQL database
(for the Postgres wrapper + builder tests).
DB_USER=yourname
DB_NAME=privex_py_db
DB_BACKEND=postgresql
LOG_LEVEL=DEBUG
Install all required dependencies:
pip3 install pipenv
pipenv install -d
Now run the tests (-v for more detailed testing output):
pipenv run pytest -rxXs -v
Metadata
Release files for privex-db 0.9.2
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 |
|---|---|---|---|---|
| privex_db-0.9.2.tar.gz | 38.9 kB | Without provenance | Details for privex_db-0.9.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| privex_db-0.9.2-py3-none-any.whl | Python 3 | none | any | Details for privex_db-0.9.2-py3-none-any.whl |
Total release size: 86.1 kB
Release files / privex_db-0.9.2.tar.gz
| Download URL | privex_db-0.9.2.tar.gz |
|---|---|
| Size | 38.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7cffa20d6b516c82d8d09dec33259ae198249aec3fe2559195cbfba0bf761d2
|
|
BLAKE2b-256 checksum How to use checksums |
2cb93de33a074ca433a6e8f6f40af68de033c1149fbc657f3ddb9456c1081d35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0
|
Release files / privex_db-0.9.2-py3-none-any.whl
| Download URL | privex_db-0.9.2-py3-none-any.whl |
|---|---|
| Size | 47.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7158831693bd426f8c380cc015cb5771e79ec70564e9063dd27592aafb88b236
|
|
BLAKE2b-256 checksum How to use checksums |
1ca5056cef9fbdff9c02bc0773040cd0efcbd376e8588a54fc05629c6a55c37f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0
|
Security for privex-db 0.9.2
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.