Over a million developers have joined DZone.

PyNuoDB: NuoDB Meets Python

· Database Zone

Build fast, scale big with MongoDB Atlas, a hosted service for the leading NoSQL database. Try it now! Brought to you in partnership with MongoDB.

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.

Now it's easier than ever to get started with MongoDB, the database that allows startups and enterprises alike to rapidly build planet-scale apps. Introducing MongoDB Atlas, the official hosted service for the database on AWS. Try it now! Brought to you in partnership with MongoDB.


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

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

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 }}