Skip to main content

Official Python SDK for Plystra.

Project description

plystra

Official Python SDK for Plystra Core v1.0.

PyPI package name: plystra Repository name: plystra/python-sdk

Requires Python 3.10 or newer.

Install

pip install plystra

Synchronous Usage

For production backend code, prefer passing a server-side access token or API key that was issued outside the request path. Keep password login available for admin tools and bootstrap flows, not for routine service-to-service checks.

Using an API key:

from plystra import Plystra

with Plystra("https://plystra.internal", api_key="ply_ak_...") as plystra:
    decision = plystra.authz.check(
        actor={
            "user_id": "user_alice",
            "space_id": "space_acme",
            "member_id": "member_finance_reviewer",
            "user_member_id": "um_alice_finance_reviewer",
        },
        resource_type="invoice",
        resource_id="invoice_001",
        action="approve",
    )

Using an access token received from your frontend or gateway session:

from plystra import Plystra

with Plystra("https://plystra.internal", access_token=session["plystra_access_token"]) as plystra:
    print(plystra.authz.check(action="approve", resource_type="invoice", resource_id="invoice_001"))

Access-token calls may omit actor; Core uses the token's active actor. API key calls must pass the nested actor explicitly.

Attach an application request id to a group of calls with with_request_id:

from plystra import Plystra

with Plystra("https://plystra.internal", access_token=session["plystra_access_token"]) as plystra:
    scoped = plystra.with_request_id("req_01HY...")
    decision = scoped.authz.check(
        resource_type="invoice",
        resource_id="invoice_001",
        action="approve",
    )

Password login is still supported:

from plystra import Plystra

with Plystra("http://localhost:8080") as plystra:
    plystra.auth.login("alice@example.com", "plystra-demo")

    # Core rotates refresh tokens. Omitting the argument uses the stored one.
    plystra.auth.refresh()

    decision = plystra.authz.check(
        actor={
            "user_id": "user_alice",
            "space_id": "space_acme",
            "member_id": "member_finance_reviewer",
            "user_member_id": "um_alice_finance_reviewer",
        },
        resource_type="invoice",
        resource_id="invoice_001",
        action="approve",
    )

    print(decision["decision"])

Registration is disabled by default in Core. When an operator enables it and gives you a registration token:

with Plystra("https://plystra.internal") as plystra:
    plystra.auth.register(
        email="founder@example.com",
        password="long-enough-password",
        space_name="Founder Space",
        registration_token=registration_token,
    )

Asynchronous Usage

import asyncio
from plystra import AsyncPlystra


async def main() -> None:
    async with AsyncPlystra("https://plystra.internal", api_key="ply_ak_...") as plystra:
        decision = await plystra.authz.check(
            actor={
                "user_id": "user_alice",
                "space_id": "space_acme",
                "member_id": "member_finance_reviewer",
                "user_member_id": "um_alice_finance_reviewer",
            },
            resource_type="invoice",
            resource_id="invoice_001",
            action="approve",
        )
        print(decision["decision"])


asyncio.run(main())

Modules

The SDK exposes v1.0 Core modules as attributes:

  • system
  • auth
  • actor
  • admin
  • api_keys
  • users
  • spaces
  • groups
  • members
  • user_members
  • roles
  • member_roles
  • permissions
  • role_permissions
  • resource_types
  • resources
  • authz
  • audit
  • data
  • plugins
  • templates

Non-public endpoints require either a Bearer session whose user has an active admin grant or a scoped API key with matching permission keys.

Keep SDK tokens in a server-side encrypted session store. login() and refresh() update access_token and refresh_token on the client; call plystra.tokens() when you need to persist the rotated token pair.

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

plystra-1.0.0rc6.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plystra-1.0.0rc6-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file plystra-1.0.0rc6.tar.gz.

File metadata

  • Download URL: plystra-1.0.0rc6.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for plystra-1.0.0rc6.tar.gz
Algorithm Hash digest
SHA256 1ab332905f114365cb0c0b92bf7d44e69fc5e285b39152f9848ab44de896e16e
MD5 80f5eb1e4fe41f1def61d07b2f88efaf
BLAKE2b-256 1b3f7439b5fdbd656ce30e8e3d85a200a48f030bfd0ecda29f9696fea8571465

See more details on using hashes here.

Provenance

The following attestation bundles were made for plystra-1.0.0rc6.tar.gz:

Publisher: publish.yml on plystra/python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plystra-1.0.0rc6-py3-none-any.whl.

File metadata

  • Download URL: plystra-1.0.0rc6-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for plystra-1.0.0rc6-py3-none-any.whl
Algorithm Hash digest
SHA256 afca2e6cb68ad2ef578ce004eb5e4dc84f1d1aa4b997613f7934f753e9eb960b
MD5 b5e4672310bdf66c29b9894fbfe6bf93
BLAKE2b-256 f3c74bceb112971b93d5453b4670941117a073afde4707cd9edb084b60717993

See more details on using hashes here.

Provenance

The following attestation bundles were made for plystra-1.0.0rc6-py3-none-any.whl:

Publisher: publish.yml on plystra/python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page