grano-client: Python API client¶
grano is extended by a comprehensive Python client library that can be used to edit projects, data schemata, entities and their relations remotely:
import granoclient
client = granoclient.Grano()
for project in client.projects:
print project.label
project = client.get('my-project')
project.label = 'New title'
project.save()
data = {'schemata': ['base'], 'properties': {'name': {'value': 'Alice'}}}
alice = project.entities.create(data)
data = {'schemata': ['base'], 'properties': {'name': {'value': 'Bob'}}}
bob = project.entities.create(data)
rel = {'schema': 'my-schema', 'source': alice, 'target': bob, 'properties': {}}
project.relations.create(rel)
query = project.entities.query().filter('properties-name', 'Alice')
for entity in query:
print entity.properties.get('name').get('value')
Installation¶
The easiest way to install the client is via the Python package index and pip/easy_install:
pip install grano-client
If you want to develop the client library’s code, check out the repository and set up dependencies etc. with the command:
python setup.py develop
grano-client depends on requests newer than 2.2.
Configuration¶
Several aspects of grano-client can be configured, including the host name of the grano server and the API key that is to be used for authentication. To determine these settings, the library will evaluate the following configuration sources in given order:
- Read the ~/.grano.ini file in the user’s home directory. The file is a simple .ini configuration as detailed below.
- Check the contents of the following environment variables: GRANO_HOST, GRANO_APIKEY.
- Evaluate the keyword arguments passed into the constructor of granoclient.Grano.
A simple configuration file for grano-client might look like this:
[client]
host = http://beta.grano.cc
# see user profile in grano:
api_key = xxxxxxxxxxxxxxx