An easy to use python driver for ArangoDB with built-in validation


Keywords
database, ORM, nosql, arangodb, driver, validation, arango, graph-database, nosql-data-storage, nosql-database, nosql-databases, python
License
MulanPSL-2.0
Install
pip install pyArango==2.1.1

Documentation

pyArango

downloads

downloads_month

downloads_week

image

image

image

NoSQL is really cool, but in this harsh world it is impossible to live without field validation.

WARNING: The last versions of pyArango are only compatible with ArangoDB 3.X. For the old version checkout the branch ArangoDBV2

Key Features

pyArango is geared toward the developer. It's here to help to you develop really cool apps using ArangoDB, really fast.

  • Light and simple interface
  • Built-in validation of fields on setting or on saving
  • Support for all index types
  • Supports graphs, traversals and all types of queries
  • Caching of documents with Insertions and Lookups in O(1)

Collections are treated as types that apply to the documents within. That means you can define a Collection and then create instances of this Collection in several databases. The same goes for graphs.

In other words, you can have two databases, cache_db and real_db, each of them with an instance of a Users Collection. You can then be assured that documents of both collections will be subjected to the same validation rules. Ain't that cool?

You can be 100% permissive or enforce schemas and validate fields on set, on save or both.

Installation

Supports python 2.7 and 3.5.

From PyPi:

pip install pyArango

For the latest version:

git clone https://github.com/tariqdaouda/pyArango.git
cd pyArango
python setup.py develop

Full documentation

This is the quickstart guide; you can find the full documentation here.

Initialization and document saving

Queries : AQL

Queries : Simple queries by example

PyArango supports all types of simple queries (see collection.py for the full list). Here's an example query:

Queries : Batches

Defining a Collection and field/schema Validation

PyArango allows you to implement your own field validation. Validators are simple objects deriving from classes that inherit from Validator and implement a validate() method:

In addition, you can also define collection properties (creation arguments for ArangoDB) right inside the definition:

A note on inheritence

There is no inheritance of the "_validation" and "_fields" dictionaries. If a class does not fully define its own, the defaults will be automatically assigned to any missing value.

Creating Edges

Linking Documents with Edges

Geting Edges linked to a vertex

You can do it either from a Document or an Edges collection:

Creating a Graph

By using the graph interface you ensure for example that, whenever you delete a document, all the edges linking to that document are also deleted:

Creating a Satellite Graph -----------------

If you want to benefit from the advantages of satellite graphs, you can also create them of course. Please read the official ArangoDB Documentation for further technical information.

Document Cache

pyArango collections have a caching system for documents that performs insertions and retrievals in O(1):

Statsd Reporting

pyArango can optionally report query times to a statsd server for statistical evaluation:

import statsd from pyArango.connection import Connection statsdclient = statsd.StatsClient(os.environ.get('STATSD_HOST'), int(os.environ.get('STATSD_PORT'))) conn = Connection('http://127.0.0.1:8529', 'root', 'opensesame', statsdClient = statsdclient, reportFileName = '/tmp/queries.log')

It's intended to be used in a two phase way: (we assume you're using bind values - right?)
  • First run, which will trigger all usecases. You create the connection by specifying statsdHost, statsdPort and reportFileName. reportFilename will be filled with your queries paired with your hash identifiers. It's reported to statsd as 'pyArango<hash>'. Later on you can use this digest to identify your queries to the gauges.
  • On subsequent runs you only specify statsdHost and statsdPort; only the request times are reported to statsd.

Examples

More examples can be found in the examples directory. To try them out change the connection strings according to your local setup.

Debian Dependency Graph

If you are on a Debian / Ubuntu you can install packages with automatic dependency resolution. In the end this is a graph. This example parses Debian package files using the deb_pkg_tools, and will then create vertices and edges from packages and their relations.

Use examples/debiangraph.py to install it, or examples/fetchDebianDependencyGraph.py to browse it as an ascii tree.

ArangoDB Social Graph

You can create the ArangoDB SocialGraph using examples/createSocialGraph.py. It resemples The original ArangoDB Javascript implementation: in python.