Skip to content
Pure-python SQL driver implementation.
Python CSS Makefile
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
pynuodb [DB-27560],[DB-27563] Remove convert hostname to ip addr (#144) Aug 5, 2019
test-performance
tests
.coveragerc Clarify client protocol version handling. May 27, 2018
.gitignore [DB-13147] Fix testConnection() method. Nov 18, 2015
.gitlab-ci.yml
.travis.yml
CONTRIBUTING.rst documentation of LC_CTYPE Aug 3, 2015
LICENSE
MANIFEST.in Use standard setuptools, move to RST format for README so the pypi si… May 27, 2015
Makefile Makefile: Cleanup, and add rules for using virtualenv May 27, 2018
README.rst README: Update to HTTPS references Jul 11, 2019
epydoc.css Added Epydoc support in the makefile Jul 1, 2015
requirements.txt Add back old python-only transform as fallback Mar 13, 2019
run_tests.py cleanup runtests error reporting for travis Feb 20, 2014
setup.py Misc cleanup per code review Jul 12, 2019
test_requirements.txt Updated dependencies Jun 18, 2015

README.rst

NuoDB - Python

Test Results Dependency Verification Code Health

This package contains the community driven pure-Python NuoDB client library that provides both a standard PEP 249 SQL API, a NuoDB administration API. This is a community driven driver with limited support and testing from NuoDB.

Requirements

  • Python -- one of the following:
  • NuoDB -- one of the following:

If you haven't done so already, Download and Install NuoDB.

Installation

The last stable release is available on PyPI and can be installed with pip:

$ pip install pynuodb

Alternatively (e.g. if pip is not available), a tarball can be downloaded from GitHub and installed with Setuptools:

$ curl -L https://github.com/nuodb/nuodb-python/archive/master.tar.gz | tar xz
$ cd nuodb-python*
$ python setup.py install
$ # The folder nuodb-python* can be safely removed now.

Example

Here is an example using the PEP 249 API that creates some tables, inserts some data, runs a query, and cleans up after itself:

import pynuodb

options = {"schema": "test"}
connect_kw_args = {'database': "test", 'host': "localhost", 'user': "dba", 'password': "dba", 'options': options}

connection = pynuodb.connect(**connect_kw_args)
cursor = connection.cursor()
try:
    stmt_drop = "DROP TABLE IF EXISTS names"
    cursor.execute(stmt_drop)

    stmt_create = """
    CREATE TABLE names (
        id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
        name VARCHAR(30) DEFAULT '' NOT NULL,
        age INTEGER DEFAULT 0
    )"""
    cursor.execute(stmt_create)

    names = (('Greg', 17,), ('Marsha', 16,), ('Jan', 14,))
    stmt_insert = "INSERT INTO names (name, age) VALUES (?, ?)"
    cursor.executemany(stmt_insert, names)

    connection.commit()

    age_limit = 15
    stmt_select = "SELECT id, name FROM names where age > ? ORDER BY id"
    cursor.execute(stmt_select, (age_limit,))
    print("Results:")
    for row in cursor.fetchall():
        print("%d | %s" % (row[0], row[1]))

finally:
    cursor.execute(stmt_drop)
    cursor.close()
    connection.close()

All sorts of management and monitoring operations may be performed through the NuoDB Python API, a few below include listening to database state, and shutting down a database:

import time
from pynuodb import entity

class DatabaseListener(object):
    def __init__(self):
        self.db_left = False

    def process_left(self, process):
        print("process left: %s" % process)

    def database_left(self, database):
        print("database shutdown: %s" % database)
        self.db_left = True

listener = DatabaseListener()
domain = entity.Domain("localhost", "domain", "bird", listener)
try:
    database = domain.get_database("test")
    if database is not None:
        database.shutdown(graceful=True)
        for i in range(1, 20):
            time.sleep(0.25)
            if listener.db_left:
                time.sleep(1)
                break
finally:
    domain.disconnect()

For further information on getting started with NuoDB, please refer to the Documentation.

Resources

DB-API 2.0: https://www.python.org/dev/peps/pep-0249/

NuoDB Documentation: https://doc.nuodb.com/Latest/Default.htm

License

PyNuoDB is licensed under a BSD 3-Clause License.

You can’t perform that action at this time.