Skip to main content

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 http://graphalchemy.readthedocs.org

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])
session.commit()


# 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):

https://github.com/jtratner/graphalchemy/raw/master/docs/images/readme-example.png

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 files for graph-alchemy 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graph-alchemy 0.1.0
File Size Uploaded
graph-alchemy-0.1.0.tar.gz 12.2 kB Details

Release files / graph-alchemy-0.1.0.tar.gz

Download URL graph-alchemy-0.1.0.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
54481aa54345c74fe926519a6bb93ab4c0c2f1ae6f2514e4ba637c594c3d2d46
BLAKE2b-256 checksum
How to use checksums
ec0fb82e94205882daa67d9fd3d847e0bd876ed1c4b50a2e9300065272256967
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page