Habitat repository and authorization API
pip install pennprov==2.2.12.dev55
Habitat API
This Python package is automatically generated by the Swagger Codegen project:
Python 2.7 and 3.4+; Docker and Docker Compose, if setting up the server in a Docker container.
You can install with pip
pip install pennprov
(you may need to run pip
with root permission: sudo pip install pennprov
)
Then import the package:
import pennprov
The following illustrates a simple use of the API to obtain a authentication token and then store and retrieve nodes and edges.
"""Example usage of pennprov client"""
from __future__ import print_function
from pprint import pprint
import pennprov
from pennprov.rest import ApiException
def main():
"""Get a token and store a node"""
# create instances of the API classes
configuration = pennprov.configuration.Configuration()
configuration.host = "http://localhost:8088"
api_client = pennprov.ApiClient(configuration)
auth_api = pennprov.AuthenticationApi(api_client)
prov_api = pennprov.ProvenanceApi(api_client)
prov_dm_api = pennprov.ProvDmApi(api_client)
username = "YOUR_USERNAME"
credentials = pennprov.UserCredentials(
"YOUR_PASSWORD")
graph_name = "my_graph"
try:
# One-time initialization of client with a JWT token for
# authentication.
web_token = auth_api.get_token_route(username, credentials)
token = web_token.token
print("Setting token %s\n" % token)
configuration.api_key["api_key"] = token
# Once api_key is set we can call services. For example,
# store_prov_node
prov_token_value = "my_prov_token"
stream = pennprov.IDModel("my_stream.0")
prov_location = pennprov.ProvLocationModel(
stream=stream,
field="my_source",
position=[1, 2])
data = [pennprov.FieldModel(
name="my_boolean_field", type="BOOLEAN", value="true")]
tuple_with_schema = pennprov.TupleWithSchemaModel(
schema_name="my_schema", tuple=data, lookup_keys=[])
body = pennprov.StoreNodeModel(
prov_specifier=prov_location, tuple_with_schema=tuple_with_schema)
prov_api.create_provenance_graph(graph_name)
prov_api.store_provenance_node(graph_name, prov_token_value, body)
# Retrieve the data from the node
response = prov_api.get_provenance_data(graph_name, prov_token_value)
pprint(response)
# We can also use the ProvDmApi to create PROV data model specific nodes and relations.
prov_dm_graph = 'my PROV DM graph'
namespace = 'http://example.com'
prov_api.create_provenance_graph(prov_dm_graph)
inputProvId = pennprov.QualifiedName(namespace, 'input1')
inputEntity = pennprov.NodeModel(type='ENTITY', attributes=[pennprov.Attribute(
name=pennprov.QualifiedName(namespace, 'stringAttr'), value='paramValue', type='STRING')])
prov_dm_api.store_node(resource=prov_dm_graph,
token=inputProvId, body=inputEntity)
outputProvId = pennprov.QualifiedName(namespace, 'output1')
outputEntity = pennprov.NodeModel(type='ENTITY', attributes=[pennprov.Attribute(
name=pennprov.QualifiedName(namespace, 'longAttr'), value=16, type='LONG')])
prov_dm_api.store_node(resource=prov_dm_graph,
token=outputProvId, body=outputEntity)
wasDerivedFrom = pennprov.RelationModel(
type='DERIVATION', subject_id=outputProvId, object_id=inputProvId,
attributes=[pennprov.Attribute(name=pennprov.QualifiedName(namespace, 'booleanAttr'), value=True, type='BOOLEAN'),
pennprov.Attribute(name=pennprov.QualifiedName(namespace, 'anotherStringAttr'), value='attrValue', type='STRING')])
prov_dm_api.store_relation(resource=prov_dm_graph, body=wasDerivedFrom, label='wasDerivedFrom')
# And stil use the base ProvenanceApi to retrieve information about the PROV DM graph
edge = prov_api.get_edges_from(prov_dm_graph, outputProvId)
pprint(edge)
except ApiException as api_exception:
print("Exception when calling server: %s\n" % api_exception)
if __name__ == '__main__':
main()
If you want to have a simple Docker container to test the above, do the following.
cd docker-container
docker-compose up
Then (after waiting some time!) open your Web browser to http://localhost:8088 and click on Sign up
. Create a new user called YOUR_USERNAME
with password YOUR_PASSWORD
.
All URIs are relative to http://localhost:8088
Class | Method | HTTP request | Description |
---|---|---|---|
AuthenticationApi | add_credential | POST /auth/services/{service}/user/{username} | Adds a service credential for the user |
AuthenticationApi | add_group | POST /auth/organizations/{organization}/group/{group} | Adds a permissions group to an organization |
AuthenticationApi | add_organization | POST /auth/organizations/{orgname} | Adds an organization |
AuthenticationApi | add_subgroup_to_group | POST /auth/groups/{groupname}/group/{subgroup} | Adds a subgroup to a group |
AuthenticationApi | add_user_to_group | POST /auth/groups/{groupname}/user/{username} | Adds a user to a group |
AuthenticationApi | add_user_to_organization | POST /auth/organizations/{orgId}/user/{username} | Adds a user to an organization |
AuthenticationApi | create_new_user | POST /auth/credentials/{username} | Creates a new user |
AuthenticationApi | get_group_from_id | GET /auth/groups/id/{groupId} | Gets a group name from its integer ID |
AuthenticationApi | get_group_id | GET /auth/groups/name/{groupName} | Gets a group's ID from its name |
AuthenticationApi | get_group_ids_for_user | GET /auth/credentials/{username}/groups/id | Gets the IDs of groups in which a user is directly a member |
AuthenticationApi | get_groups_for_user | GET /auth/credentials/{username}/groups | Gets the groups in which a user is directly a member |
AuthenticationApi | get_organization_from_id | GET /auth/organizations/id/{orgId} | Gets an organization name from its integer ID |
AuthenticationApi | get_organization_id | GET /auth/organizations/name/{orgName} | Gets an organization ID from its name |
AuthenticationApi | get_parent_group_ids | GET /auth/groups/id/{groupId}/parents/id | Gets the IDs of parent groups |
AuthenticationApi | get_parent_groups | GET /auth/groups/name/{groupName}/parents/name | Gets the groups in which a user is directly a member |
AuthenticationApi | get_token_route | POST /auth/tokens/{username} | Requests a new token |
AuthenticationApi | get_user_info | GET /auth/credentials/{username}/info | Gets a user's info |
AuthenticationApi | is_registered | GET /auth/services/{service}/user/{username} | Returns whether a user credential is valid for a service |
AuthenticationApi | is_valid_credential | POST /auth/services/local/user/{username}/credential | Returns whether a local user credential is valid |
AuthenticationApi | update_user | PUT /auth/credentials/{username} | Updates user properties |
PermissionApi | add_permission | POST /perms/types/{permname} | Adds a new labeled permission type |
PermissionApi | get_group_permissions_on | GET /perms/objects/{object}/group/{groupName} | Gets the group's permissions on an object |
PermissionApi | get_object_ids | GET /perms/name/{permname}/user/{username} | Gets the object ids for which the user has the given permission |
PermissionApi | get_permission_from_id | GET /perms/id/{id}/name | Gets a permission's name from its integer ID |
PermissionApi | get_permission_id | GET /perms/name/{name}/id | Gets a permission's ID from its name |
PermissionApi | get_user_permissions_on | GET /perms/objects/{object}/user/{username} | Gets the user's permissions on an object |
PermissionApi | grant_group_permission_on | POST /perms/objects/{object}/group/{groupName}/{permname} | Grants a group a permission on an object |
PermissionApi | grant_user_permission_on | POST /perms/objects/{object}/user/{username}/{permname} | Grants a user a permission on an object |
PermissionApi | revoke_group_permission_on | DELETE /perms/objects/{object}/group/{groupName}/{permname} | Revokes a group a permission on an object |
PermissionApi | revoke_user_permission_on | DELETE /perms/objects/{object}/user/{username}/{permname} | Revokes a user a permission on an object |
ProvDmApi | store_node | PUT /provdm/graphs/{resource}/nodes/{token} | Store a PROV DM node |
ProvDmApi | store_relation | POST /provdm/graphs/{resource}/links/{label} | Store a relation between PROV DM tokens |
ProvenanceApi | create_or_reset_provenance_graph | PUT /provenance/graphs/reset/{resource} | Create a provenance graph if it doesn't exist, or overwrite it if it does |
ProvenanceApi | create_provenance_graph | PUT /provenance/graphs/{resource} | Create a provenance graph |
ProvenanceApi | get_connected_from | GET /provenance/graphs/{resource}/nodes/{token}/neighbors/out | Get the outgoing neighbors of the given prov token |
ProvenanceApi | get_connected_to | GET /provenance/graphs/{resource}/nodes/{token}/neighbors/in | Get the incoming neighbors of the given prov token |
ProvenanceApi | get_edges_from | GET /provenance/graphs/{resource}/nodes/{token}/links/out | Get the outgoing edges of the given prov token |
ProvenanceApi | get_edges_to | GET /provenance/graphs/{resource}/nodes/{token}/links/in | Get the incoming edges of the given prov token |
ProvenanceApi | get_provenance_data | GET /provenance/graphs/{resource}/nodes/{token} | Get the tuple associated with a provenance token |
ProvenanceApi | get_provenance_location | GET /provenance/graphs/{resource}/nodes/{token}/location | Get the location of a provenance token |
ProvenanceApi | get_provenance_nodes | GET /provenance/graphs/{resource}/nodes | Get the provenance graph's nodes |
ProvenanceApi | get_subgraphs | POST /provenance/graphs/{resource}/subgraphs | Get a provenance graph as a sequence of subgraphs |
ProvenanceApi | store_provenance_link | POST /provenance/graphs/{resource}/links | Store a provenance link between tokens |
ProvenanceApi | store_provenance_node | PUT /provenance/graphs/{resource}/nodes/{token} | Store a provenance token with its location |
ProvenanceApi | store_subgraph | POST /provenance/graphs/{resource}/subgraphs/store | Store a subgraph to a provenance graph |