Vilocify SDK built atop APIv2
Project description
Vilocify SDK and CLI tool
The Python SDK for Vilocify, built using Vilocify's APIv2 JSON:API. This project also includes an example CLI tool to manage Vilocify Monitoring Lists.
Prerequisites
The Vilocify SDK needs Python 3.12 or newer.
CLI usage
- Get pipx
- Install the CLI with
pipx install vilocify-sdk - Run
vilocify --helpfor documentation of the bundled example CLI tool
SDK usage
The SDK is built on Vilocify's API.
We recommend you also take a quick look at the raw API docs at https://portal.vilocify.com/documentation.
In particular, study the "API resources" section and filter[...][...] parameters of main resources.
Those will come in handy for understanding the models of the SDK and arguments that can be used in .where() methods.
Installation
Get vilocify-sdk from PyPI.
If you use Poetry get it with poetry add vilocify-sdk.
Authentication
You can generate an API Token at https://ui.portal.vilocify.com/api-tokens.
By default, authentication for the SDK is configured through the VILOCIFY_API_TOKEN environment variable.
Alternatively, the token can be set programmatically:
from vilocify import api_config
api_config.token = "<your token here>"
Examples
Inviting a new member into your org
Note that this code needs a token with "admin" role.
from vilocify.models import Membership
m = Membership(username="John Doe", email="john.doe@example.com", role="user", expires_at="2025-10-30T00:00:00Z")
m.create()
print(m.invitation_state)
print(m.created_at)
Creating a monitoring list
from vilocify.models import MonitoringList, Subscription, Component, Membership
# Creating a new monitoring list automatically adds the authenticated user as 'owner'
ml = MonitoringList(name="Example list", comment="created by the Vilocify SDK")
ml.components = [
Component(id="40866"),
Component(id="148860")
]
ml.create()
# Add a second subscriber to the list.
sub = Subscription(role="reader")
sub.monitoring_list = ml
sub.membership = Membership.where("email", "eq", "john.doe@example.com").first()
sub.create()
for subscription in ml.subscriptions:
print(subscription.membership.email, "-", subscription.role)
Listing notifications for a monitoring list
from vilocify.models import MonitoringList, Notification
ml = MonitoringList.where("name", "eq", "Example list").first()
# Find Vilocify notifications for the monitoring list since 2023
notifications = Notification.where("monitoringLists.id", "any", ml.id).where("createdAt", "after", "2023-01-01T00:00:00Z")
for n in notifications:
print(n.title)
Filtering
To filter models by supported attributes, use the .where() method, which takes three arguments.
The three arguments map 1-to-1 to filter parameters described in the API Docs.
Take for example following request with a filter parameter from the docs:
GET /api/v2/notifications?filter[monitoringLists.id][any]=8c63252a-893e-4563-876b-a45ac9bdfff2
The corresponding Python code is
Notification.where("monitoringLists.id", "any", "8c63252a-893e-4563-876b-a45ac9bdfff2")
The third parameter of .where() can either be a string or a list of strings.
Note that the SDK does not perform further validations which operators accept lists and which don't; lists simply get concatenated to comma-separated strings.
Check the API docs which filters support multiple values.
Sorting
Sorting is handled by .asc() and .desc().
Check the documentation of the sort parameter in top-level GET /api/v2/{resources} in the API Docs for available sorters.
The Vilocify API can only sort by a single attribute and does not support sorting by multiple attributes.
The SDK will raise an exception when attempting to sort an already sorted request.
Relationships
The models.py module defines the SDK models and their relationships, which closely reflects the "API Resources" drawing of the API Docs. Relationships cannot be set through the model constructor, but instead must be set using assignment. For example:
sub = Subscription(role="user") # role is an attribute
sub.membership = Membership(id="<a_membership_id_here>") # `.membership` is a to-one relation
sub.monitoring_list = MonitoringList(id="<a_ml_id_here>") # `.monitoring_list` is a to-one relation
sub.create() # Performs the API request to create the subscription
ml = MonitoringList(name="Example list") # name is an attribute
ml.components = [ # components is a to-many relationship
Component(id="40866"),
Component(id="148860")
]
ml.create() # Creates a monitoring list with the two given components
Updating to-many relationships
The SDK provides two mechanisms to update to-many relationships.
One replaces all existing relationships and is not immediate, but needs a call to .update().
The other extends the existing relationship and is immediate.
For example
ml = MonitoringList.first()
ml.components = [ # Replaces all components on the monitoring list, no request is sent, yet.
Component(id="1"),
Component(id="2")
]
ml.update() # Commit the change to the Vilocify API
ml = MonitoringList.first()
ml.components.extend(Component(id="3"), Component(id="5")) # Adds component with IDs 1 and 2, and immediately sends the change to the API backend
Proxy setup
The SDK uses a requests.Session() to handle its HTTP requests, which picks up the proxy settings from the https_proxy environment variable as documented here.
To override that behavior do the following:
from vilocify import api_config
api_config.client.trust_env = False
api_config.client.proxies = { "https": "https://your.proxy:8080" }
Contributing
See Contributing.md.
License
Copyright (c) 2025 Siemens AG
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vilocify_sdk-0.5.0.tar.gz.
File metadata
- Download URL: vilocify_sdk-0.5.0.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19792d56b975c9fa49bb74698bf4339295a84d0a4a5f2a8bd8f7e469f99eb4ce
|
|
| MD5 |
4fb78b4973dd06529996e1b80ae3da81
|
|
| BLAKE2b-256 |
207a5503b7ddeb285aeb5869bfeee980c6b0ef866832870a83902e2e177494fe
|
Provenance
The following attestation bundles were made for vilocify_sdk-0.5.0.tar.gz:
Publisher:
release.yml on siemens/vilocify-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vilocify_sdk-0.5.0.tar.gz -
Subject digest:
19792d56b975c9fa49bb74698bf4339295a84d0a4a5f2a8bd8f7e469f99eb4ce - Sigstore transparency entry: 214003537
- Sigstore integration time:
-
Permalink:
siemens/vilocify-sdk-python@45db422cacf5744136dab750a0933ed9c2018c7e -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/siemens
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@45db422cacf5744136dab750a0933ed9c2018c7e -
Trigger Event:
push
-
Statement type:
File details
Details for the file vilocify_sdk-0.5.0-py3-none-any.whl.
File metadata
- Download URL: vilocify_sdk-0.5.0-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
198c7d0f775a2f698174764a7ab0dd1a04b85964c784dd6946c39aeec7940452
|
|
| MD5 |
9932c0732aefd080a349bfc8b304cc50
|
|
| BLAKE2b-256 |
1e904f571dabda9fdc9556e7c4cb689954bc30a87fa6a885dfdba752f7c0422a
|
Provenance
The following attestation bundles were made for vilocify_sdk-0.5.0-py3-none-any.whl:
Publisher:
release.yml on siemens/vilocify-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vilocify_sdk-0.5.0-py3-none-any.whl -
Subject digest:
198c7d0f775a2f698174764a7ab0dd1a04b85964c784dd6946c39aeec7940452 - Sigstore transparency entry: 214003538
- Sigstore integration time:
-
Permalink:
siemens/vilocify-sdk-python@45db422cacf5744136dab750a0933ed9c2018c7e -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/siemens
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@45db422cacf5744136dab750a0933ed9c2018c7e -
Trigger Event:
push
-
Statement type: