Skip to main content

Privex's Python Database helpers and wrappers (mini ORM)

Project description

Privex's Python Database Library

Build Status Codecov PyPi Version License Button PyPI - Downloads PyPI - Python Version GitHub last commit

|                 © 2019 Privex Inc.                |
|                    |
|                                                   |
|        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.   ( )

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("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(, '-',
# Output: 2 - Orange

q = db.builder('items')
# Privex QueryBuilder's support chaining similar to Django's ORM'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: {}   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'}, ... ]


Read the 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
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
# 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).


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

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for privex-db, version 0.9.2
Filename, size File type Python version Upload date Hashes
Filename, size privex_db-0.9.2-py3-none-any.whl (47.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size privex_db-0.9.2.tar.gz (38.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page