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"])

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.0rc5.tar.gz (14.5 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.0rc5-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: plystra-1.0.0rc5.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for plystra-1.0.0rc5.tar.gz
Algorithm Hash digest
SHA256 3329ff45da2bbf993abc1b4c868e64fdf921e699257ce0457ec986279b9abeee
MD5 decd9ebf4a930eae74042c8836b568a9
BLAKE2b-256 fa7e71e2f2b14aec8349bb81ae3dc4f022d9903e8666f50c4e26a550eaf31566

See more details on using hashes here.

File details

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

File metadata

  • Download URL: plystra-1.0.0rc5-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for plystra-1.0.0rc5-py3-none-any.whl
Algorithm Hash digest
SHA256 9fc68f675413ccf7bc60ae2c8b145b43e9eb255a2ddde7f7f9069acdb3667ca7
MD5 647f81ce2425cecca5ab5292f5ae08e6
BLAKE2b-256 d8d76cc44fc3d357263726f086b8814c32c518413f2d9a13474ef1f6e0372525

See more details on using hashes here.

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