Attributes and Annotations

To run this example, you'll need the Ovation Python API. Install with pip:

pip install ovation

In [ ]:
from ovation.session import connect

from pprint import pprint
from getpass import getpass

Connection

You use a connection.Session to interact with the Ovaiton REST API. Use the connect method to create an authenticated Session. You can provide your Ovation password with the password= parameter, but please keep your Ovation password secure. Don't put your password in your source code. It's much better to let connect prompt you for your password when needed. For scripts run on the server, it's best to provide your password via an environment variable:

connect(my_email, password=os.environ['OVATION_PASSWORD'])

for example.


In [ ]:
session = connect(input('Email: '), org=int(input("Organization (enter for default): ") or 0))

Attributes

Ovation entities have an attributes object for user data. For example, the Ovation web app uses the attributes object to store the name of a Folder or File. You can see the names of these 'built-in' attributes for each entity at https://api.ovation.io/index.html.

You can update the attributes of an entity by modifying the attributes object and PUTing the entity.


In [ ]:
project_id = input('Project UUID: ')

In [ ]:
project = session.get(session.path('projects', id=project_id))
pprint(project)

In [ ]:
# Add a new attribute
project.attributes.my_attribute = 'Wow!'

# PUT the entity to save it
project = session.put(project.links.self, entity=project)
pprint(project)

You can delete attributes by removing them from the attributes object.


In [ ]:
# Remove an attribute
del project.attributes['my_attribute']

# PUT the entity to save it
project = session.put(project.links.self, entity=project)

Annotations

Unlike attributes which must have a single value for an entity, annotations any user to add their own information to an entity. User annotations are kept separate, so one user's annotation can't interfere with an other user's. Anyone with permission to see an entity can read all annotations on that entity, however.

Annotations can be keyword tags, properties (key-value pairs), text notes, and events.


In [ ]:
# Create a new keyword tag
session.post(project.links.tags, data={'tags': [{'tag': 'mytag'}]})

In [ ]:
# Get the tags for project
tags = session.get(project.links.tags)
pprint(tags)

In [ ]:
# Delete a tag
session.delete(project.links.tags + "/" + tags[0]._id)