Printemps is Python server that let you access databases suppported by Blueprints from Python. It’s easy to setup and get running and will write only Python.
printemps-client allow you to access the python-blueprints API from a remote server.
If you look for performance I recommand you to have a look at Bulbsflow.
If you’ve setup a remote OrientDB you won’t need printemps-client and will be just fine, with what I think to be an efficient solution to do graph database work fully in Python, with python-blueprint. Moreover OrientDB is according to some benchmarks faster.
To use Printemps client you will need to start by python-blueprints documentation, and come back here after, it a tiny API, you will be here back soon, I promise.
For a development setup you will need both the server and client, which can be installed with the following commands, if you already installed python-blueprints:
$> pip install printemps printemps-client
You can now run one the supported database with the following commands:
$> printemps 127.0.0.1 8888 neo4j /tmp/ $> printemps 127.0.0.1 8888 orientdb local:/tmp/
You are ready! Full tutorial ensue.
The client printemps_client.PrintempsClient allow you to connect to a Printemps server, if you provided an authkey it takes authkey as parameters. For the purpose of this tutorial there isn’t any, so the following code will do the job:
from printemps_client import PrintempsClient client = PrintempsClient('127.0.0.1', 8888)
Given the server has only one database thread, to maximize the number of concurrent connections the client opens a connection with the server for each query.
But what is a query? A Python function.
Here are two example queries taken from the germinal example.
def create(graph, result, person): """Create a vertex for person if there isn't any, and index it""" persons = graph.index.get('persons', graph.VERTEX) try: next(persons.get('name', person)) except StopIteration: with graph.transaction(): vertex = graph.vertex() vertex['name'] = person persons.put('name', person, vertex) def improve_link(graph, result, person, other): """Retrieve the edge between person and other and increment weight""" # retrieve person and other vertices persons = graph.index.get('persons', graph.VERTEX) person = next(persons.get('name', person)) other = next(persons.get('name', other)) # graphdb edge are directed but the relation # is undirected so we need to check both direction found = None for edge in person.outgoings(): if edge.end() == other: found = edge break if not found: for edge in person.incomings(): if edge.start() == other: found = edge break if not found: # create the edge with graph.transaction(): edge = graph.edge(person, other, 'knows') edge['weight'] = 1 else: with graph.transaction(): edge['weight'] += 1
They are functions that can be run against python-blueprints directly. They both take as first arguments graph and results. Those two parameters is all you need to make a Python function, a Printemps query. They are the only obligatory arguments of any query. graph is the object representing the graph and results is a dictionnary where you can store anything you want, it will be returned as the result of the query.
To run improve_link against the graph database you would use the following code:
client.process(improve_link, person=word, other=other)
PrintempsClient.process takes as first argument the Python function you want to take, followed by the supplemental arguments of the query as keyword arguments.
The return value is results.
The following code is an example where results is populated server-side and returned:
def stats(graph, result): """Retrieve edges statistics""" stats =  for edge in graph.edges(): start = edge.start()['name'] end = edge.end()['name'] weight = edge['weight'] stats.append((start, end, weight)) stats.sort(key=lambda x: x, reverse=True) result['stats'] = stats
It’s called the same way as improve_link except this one doesn’t take arguments:
stats = client.process(stats)
Of course there is no example of that but a function can both take supplemental arguments and «return» some result.