A Python SDK for the Perses API
Project description
perses-api-sdk
A Python SDK for the Perses API.
Requirements
- Python 3.12+
- A running Perses instance
Installation
pip install perses-api-sdk
Quick start
from perses_api import APIModel, Project, Dashboard
from perses_api.model import Metadata, ProjectSpec, DashboardSpec
from perses_api.model import Project as ProjectModel, Dashboard as DashboardModel
# Connect with a bearer token
client = APIModel(host="http://localhost:8080", token="<your-token>")
# Or connect with username/password (Basic auth)
client = APIModel(host="http://localhost:8080", username="admin", password="password")
# Create a project
projects = Project(client)
project = projects.create_project(
ProjectModel(metadata=Metadata(name="my-project"), spec=ProjectSpec())
)
# Create a dashboard inside it
dashboards = Dashboard(client)
dashboard = dashboards.create_dashboard(
"my-project",
DashboardModel(
metadata=Metadata(name="my-dashboard", project="my-project"),
spec=DashboardSpec(),
),
)
Authentication
Pass a bearer token via token=, or supply username= and password= for HTTP Basic auth. When both are provided, the token takes precedence.
# Bearer token
client = APIModel(host="http://localhost:8080", token="eyJ...")
# Basic auth
client = APIModel(host="http://localhost:8080", username="admin", password="secret")
Available clients
| Class | Scope | Description |
|---|---|---|
Project |
global | Projects |
Dashboard |
project | Dashboards |
EphemeralDashboard |
project | Ephemeral dashboards |
ProjectDatasource |
project | Datasources |
GlobalDatasource |
global | Global datasources |
ProjectVariable |
project | Variables |
GlobalVariable |
global | Global variables |
ProjectRole |
project | Roles |
GlobalRole |
global | Global roles |
ProjectRoleBinding |
project | Role bindings |
GlobalRoleBinding |
global | Global role bindings |
ProjectSecret |
project | Secrets |
GlobalSecret |
global | Global secrets |
User |
global | Users |
Plugin |
global | Plugin listing |
Migrate |
global | Grafana → Perses migration |
Validate |
global | Dashboard validation |
Configuration options
client = APIModel(
host="http://localhost:8080",
token="<token>",
timeout=30.0, # request timeout in seconds (default: 10)
http2_support=False, # enable HTTP/2 (requires httpx[http2])
num_pools=10, # max concurrent connections
retries=False, # retry failed requests
follow_redirects=True, # follow HTTP redirects
)
Examples
Datasource
from perses_api import APIModel, ProjectDatasource
from perses_api.model import Metadata, DatasourceSpec, Datasource as DatasourceModel
client = APIModel(host="http://localhost:8080", token="<token>")
ds = ProjectDatasource(client, "my-project")
created = ds.create_datasource(
DatasourceModel(
metadata=Metadata(name="prometheus", project="my-project"),
spec=DatasourceSpec(
default=True,
plugin={
"kind": "PrometheusDatasource",
"spec": {"directUrl": "http://prometheus:9090"},
},
),
)
)
Migrate a Grafana dashboard
from perses_api import APIModel, Migrate
client = APIModel(host="http://localhost:8080", token="<token>")
m = Migrate(client)
perses_dashboard = m.migrate(grafana_dashboard={"title": "My Dashboard", "panels": []})
Validate a dashboard
from perses_api import APIModel, Validate
client = APIModel(host="http://localhost:8080", token="<token>")
v = Validate(client)
v.validate(dashboard={"kind": "Dashboard", "metadata": {}, "spec": {}})
Development
Setup
# Install with test dependencies
uv sync --extra test
# Install with docs dependencies
uv sync --extra docs
Running integration tests
Requires Docker.
make integration
Or against an existing Perses instance:
PERSES_HOST=http://localhost:8080 \
PERSES_USERNAME=admin \
PERSES_PASSWORD=password \
uv run pytest tests/integration/ -v
License
Project details
Release history Release notifications | RSS feed
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 perses_api_sdk-0.1.0.tar.gz.
File metadata
- Download URL: perses_api_sdk-0.1.0.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbf6f80680538e34ba51fef51bd5c521623927015809382869058400ca7d193d
|
|
| MD5 |
dda3fd70f1a7b98e4449bde579a2e19f
|
|
| BLAKE2b-256 |
28dda61cfac5025837f68be87f3fd8e4b46c2cd880ffca4509f75496bd3b90ca
|
Provenance
The following attestation bundles were made for perses_api_sdk-0.1.0.tar.gz:
Publisher:
release.yml on ZPascal/perses_api_sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
perses_api_sdk-0.1.0.tar.gz -
Subject digest:
fbf6f80680538e34ba51fef51bd5c521623927015809382869058400ca7d193d - Sigstore transparency entry: 1839984345
- Sigstore integration time:
-
Permalink:
ZPascal/perses_api_sdk@5ec979e7aa82da3b7f72e22ee27de68297a82ba1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ZPascal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5ec979e7aa82da3b7f72e22ee27de68297a82ba1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file perses_api_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: perses_api_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 26.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db1424ba0a6ac8c81f64e9775b5ae0429067d47b2db4c676e938114fc76448ef
|
|
| MD5 |
65d321378b1086f90652087542305f57
|
|
| BLAKE2b-256 |
e6a3097ebc50fa95d9973bea3d86fac4d02e56dca68d567eb22d08611cf916bc
|
Provenance
The following attestation bundles were made for perses_api_sdk-0.1.0-py3-none-any.whl:
Publisher:
release.yml on ZPascal/perses_api_sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
perses_api_sdk-0.1.0-py3-none-any.whl -
Subject digest:
db1424ba0a6ac8c81f64e9775b5ae0429067d47b2db4c676e938114fc76448ef - Sigstore transparency entry: 1839984471
- Sigstore integration time:
-
Permalink:
ZPascal/perses_api_sdk@5ec979e7aa82da3b7f72e22ee27de68297a82ba1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ZPascal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5ec979e7aa82da3b7f72e22ee27de68297a82ba1 -
Trigger Event:
push
-
Statement type: