This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Basic Node/Edge model for SQLAlchemy

Project Description

Graph node-edge relationships in SQLAlchemy (and soon more orms) + networkx integration.

The Goal

Set up a generalized abstraction/interface for a graph that can be used across various platforms and within various frameworks that is easy and simple to use, extensible, and that easily hooks into other graphing tools (like gephi networkx, etc.)

What’s here

A basic set of node/edge abstractions + many-to-one relationships for a graph represented in SQL with SQLAlchemy

Using this package

Documentation is available at

It’s very simple to use (and examples are to come). But for now the best thing to do is to go read the docs on SQLAlchemy

A very minimal example (using an SQLite database):

from graphalchemy.sqlmodels import create_base_classes, sqlite_connect
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
Node, Edge = create_base_classes(NodeClass="Node", EdgeClass="Edge", Base=Base)
engine, session = sqlite_connect("database.db", metadata=Base.metadata)

# be sure to use unicode!!
node1 = Node(label=u"First node!")
node2 = Node(label=u"Second node!")
node3 = Node(label=u"Third node!")
edge1 = Edge.connect_nodes(node1, node2)
edge2 = Edge.connect_nodes(node1, node3)

session.add_all([node1, node2, node3, edge1, edge2])

# now we can graph it

import networkx as nx
G = nx.Graph()
G.add_edges_from([edge1, edge2])

# now we can draw this! (if you had pylab, matplotlib, etc)

And you’d get a picture that looked something like this (clearly, we haven’t added all the traits and such in, but you get the idea):

Now, obviously this is a pretty minimal example, but it shows how you can take advantage of the power of SQL joins, queries, etc, but also very easily

What’s going to be here

  1. networkx integration
  2. testing for multiple sql databases and adapters
  3. abstractions for Google App Engine, mongoalchemy, and possibly Django ORM
  4. adapter between networkx and web service requests (maybe?)

Testing coverage

Basic test suite that gets 100% line coverage for SQLAlchemy models and base models (still missing a test for Flask-SQLAlchemy). I’ve only run it on SQLite so far, but presumably it should work with other SQL databases just fine (since it uses SQLAlchemy’s declarative base)

Release History

Release History

This version
History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
graph-alchemy-0.1.0.tar.gz (12.2 kB) Copy SHA256 Checksum SHA256 Source Aug 8, 2012

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting