A client library for interacting with the Veda Platform HTTP API.
python setup.py bdist_wheel
pip install veda-platform-client
- Python 3.6+
- requests
from veda_client import VedaClient
# Initialize the client with your API URL
client = VedaClient(base_url="http://your-veda-instance.com/api")
# Authenticate with username and password
auth_result = client.authenticate("username", "password")
# After successful authentication, the client stores the ticket
# for subsequent requests
print(f"Authenticated as: {client.user_uri}")
# Check if a ticket is valid
is_valid = client.is_ticket_valid()
# Logout (invalidate ticket)
client.logout()
from veda_client.models import Individual, ValueItem
# Get a single individual
individual = client.get_individual("document:123")
# Get multiple individuals
individuals = client.get_individuals(["document:123", "document:456"])
# Create a new individual
new_individual = Individual(uri="document:123")
# Add values to the individual
new_individual.add_value("rdf:type", "v-s:Document", "uri")
new_individual.add_value("v-s:title", "Test Document", "string", "en")
# Save the individual
result = client.put_individual(new_individual)
# Update a field
update_individual = Individual(uri="document:123")
update_individual.add_value("v-s:description", "Updated description", "string", "en")
# Apply the update (using source tracking)
result = client.set_in_individual("document:123", update_individual, src="editor-application")
# Add a field
add_individual = Individual(uri="document:123")
add_individual.add_value("v-s:tag", "important", "string")
# Apply the addition
result = client.add_to_individual("document:123", add_individual)
# Remove a field
remove_individual = Individual(uri="document:123")
remove_individual.add_value("v-s:tag", "important", "string")
# Apply the removal
result = client.remove_from_individual("document:123", remove_individual)
# Delete an individual
result = client.remove_individual("document:123")
# Execute a basic query
result = client.query("'rdf:type' == 'v-s:Document'")
# Query with sorting and limit
result = client.query(
query="'rdf:type' == 'v-s:Document'",
sort="v-s:created",
limit=10
)
# Execute a stored query with parameters
params = {
"type": "v-s:Document",
"limit": 10
}
result = client.stored_query("stored-query:DocumentSearch", params)
# Upload a file
file_id = client.upload_file("path/to/document.pdf")
# Download a file
success = client.download_file(file_id, "path/to/download/document.pdf")
# Get rights for a URI
rights = client.get_rights("document:123")
# Get rights origin
rights_origin = client.get_rights_origin("document:123")
# Get membership
membership = client.get_membership("document:123")
# Get a ticket for another user (admin operation)
trusted_ticket = client.get_ticket_trusted("another_username")
Authenticate a user with login and password.
Check if the provided ticket is valid.
Get a ticket trusted for use by another user.
Logout a user and invalidate their ticket.
Retrieve information about a specific individual.
Retrieve information about multiple individuals.
put_individual(individual, prepare_events=None, assigned_subsystems=None, event_id=None, transaction_id=None, src=None, ticket=None)
Update or insert information about an individual.
put_individuals(individuals, prepare_events=None, assigned_subsystems=None, event_id=None, transaction_id=None, src=None, ticket=None)
Update or insert information about multiple individuals.
remove_individual(uri, prepare_events=None, assigned_subsystems=None, event_id=None, transaction_id=None, src=None, ticket=None)
Remove information about a specific individual.
remove_from_individual(uri, individual, prepare_events=None, assigned_subsystems=None, event_id=None, transaction_id=None, src=None, ticket=None)
Remove a specific field from the information of an individual.
set_in_individual(uri, individual, prepare_events=None, assigned_subsystems=None, event_id=None, transaction_id=None, src=None, ticket=None)
Set or update a specific field in the information of an individual.
add_to_individual(uri, individual, prepare_events=None, assigned_subsystems=None, event_id=None, transaction_id=None, src=None, ticket=None)
Add a specific field to the information of an individual.
query(query, sort=None, databases=None, reopen=None, from_=None, top=None, limit=None, trace=None, ticket=None)
Execute a full text query against the stored data.
Execute a stored query with parameters.
Retrieve the access rights for a specific URI.
Retrieve information about the origin of access rights for a specific URI.
Retrieve membership information of a specific URI.
Upload a file to the server.
Download a file from the server.
Retrieve the state of a specified operation.
The Individual
class represents an entity in the Veda Platform data model.
from veda_client.models import Individual, ValueItem
# Create a new individual
individual = Individual(uri="document:123")
# Add values to the individual
individual.add_value("rdf:type", "v-s:Document", "uri")
individual.add_value("v-s:title", "Test Document", "string", "en")
individual.add_value("v-s:created", "2023-01-01T12:00:00Z", "dateTime")
# Get values from the individual
title_values = individual.get_property("v-s:title")
first_title = individual.get_first_value("v-s:title")
# Convert to/from dictionary
individual_dict = individual.to_dict()
from_dict_individual = Individual.from_dict(individual_dict)
The client supports tracking the source of data modifications through the src
parameter in all update methods. This allows applications to identify which component made each modification:
# Create a new document from a specific application
client.put_individual(document, src="document-editor")
# Update document from another application
client.set_in_individual(document.uri, update_data, src="workflow-engine")
# Delete document from admin panel
client.remove_individual(document.uri, src="admin-panel")
The client defines several exception types for different error scenarios:
VedaError
: Base exception for all Veda client errorsVedaAuthError
: Authentication errorsVedaRequestError
: Invalid request errorsVedaResponseError
: Errors in API responsesVedaServerError
: Server errors
from veda_client import VedaClient
from veda_client.exceptions import VedaAuthError, VedaServerError
client = VedaClient("http://your-veda-instance.com/api")
try:
client.authenticate("username", "wrong_password")
except VedaAuthError as e:
print(f"Authentication failed: {e}")
try:
client.get_individual("non-existent-uri")
except VedaServerError as e:
print(f"Server error: {e}")
MIT License