Over a million developers have joined DZone.

PyNuoDB: NuoDB Meets Python

DZone's Guide to

PyNuoDB: NuoDB Meets Python

· Database Zone
Free Resource

Learn how to create flexible schemas in a relational database using SQL for JSON.

I’m excited to announce that the beta version of pynuodb, the NuoDB Python driver, is now available on Github! You can also sign up to be an official participant in the beta program. In this post I’m going to go over how to get and install pynuodb and then lay out a few quick examples of how to use it.

We wrote pynuodb as a pure Python driver, so installing it is super easy. Just make sure you have Python 2.7 and run

git clone git://github.com/nuodb/nuodb-python.git
cd nuodb-python
sudo python setup.py install

and you’ll be good to go. Being pure Python also means that pynuodb works on Mac, Linux, and Windows (although you’ll probably need to drop the ‘sudo’ above) without any dependencies (well, other than Python). While it is not technically necessary for the driver install, you will probably also want to download NuoDB and install it before continuing.

Once you have it installed you will probably notice that pynuodb is a PEP-249 Database API Specification v2.0 compliant database driver. That means that if you’ve used used any other PEP-249 database driver pynuodb should feel very familiar. But even if you haven’t, the interface is very simple. If you have the NuoDB Quickstart database running, the following bit of Python code is all you need to read some data out of the database.

import pynuodb

connection = pynuodb.connect(database = "test", host = "localhost", 
                             user = "dba", password = "goalie", 

cursor = connection.cursor()
cursor.execute("SELECT * FROM hockey")
rows = cursor.fetchall()
print rows

As you would expect, you can also create tables and insert data.

import pynuodb
from datetime import datetime

connection = pynuodb.connect(database = "test", host = "localhost", 
                             user = "dba", password = "goalie", 

cursor = connection.cursor()
               "name STRING, email STRING, is_active BOOLEAN, signup_date TIMESTAMP)")

cursor.execute("INSERT INTO users (name, email, is_active, signup_date) VALUES (?,?,?,?)", 
               ["John Smith", "john.smith@example.com", True, datetime.now()])

cursor.execute("SELECT * FROM users")
rows = cursor.fetchall()
print rows

One thing keep in mind is that as per the PEP-249 spec, pynuodb defaults toconnection.auto_commit = False. Be sure to commit after inserting data or turnauto_commit on. Otherwise your data will not be visible to other connections (or at all, after the current connection is closed).

Check out pynuodb and let us know what you come up with!

PS: Eagle-eyed observers of our Github may have also noticed the NuoDB SQLAlchemyrepository. Check back soon for more.

Create flexible schemas using dynamic columns for semi-structured data. Learn how.


Published at DZone with permission of Seth Proctor, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}