Skip to main content

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

Apache 2.0

Release files for perses-api-sdk 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for perses-api-sdk 0.1.4
File Size Uploaded
perses_api_sdk-0.1.4.tar.gz 18.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for perses-api-sdk 0.1.4
File Interpreter ABI Platform
perses_api_sdk-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 44.2 kB

Release files / perses_api_sdk-0.1.4.tar.gz

Download URL perses_api_sdk-0.1.4.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2905fb11bbbdb80c4bb7f26ee6161b385cac4cea7a25446276f84630949c864b
BLAKE2b-256 checksum
How to use checksums
8d451a2182b0b1933b47819405be502cadb7830d4f279817517433bc9a92800f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2026.

Transparency log

Release files / perses_api_sdk-0.1.4-py3-none-any.whl

Download URL perses_api_sdk-0.1.4-py3-none-any.whl
Size 26.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0aee54841593f69eea628e3fc48364b8500894819a15048049009b2a26c1160
BLAKE2b-256 checksum
How to use checksums
f7e1d53a44e8bf116e641e94df07739404f1c4bff7b8963d25f5dd29bc80ee48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page