Skip to main content

Phase Two Python SDK

license docs

📚 Documentation • 🚀 Hosted Keycloak • 🤖 Keycloak Skills • 💬 Support

The Phase Two Python SDK library provides access to the Phase Two API for server-side Python applications.

Documentation

See the API Reference

Installation

pip install phasetwo-sdk

Requires Python 3.11 or later. The import name is phasetwo.

Use

Get an access token for a service account (client credentials grant) with any OIDC library, for example python-keycloak, and pass it to the SDK's Configuration. The host is your Keycloak base URL followed by /realms.

import json
import time

from phasetwo import (
    ApiClient,
    Configuration,
    EventRepresentation,
    EventsApi,
    OrganizationRepresentation,
    OrganizationsApi,
)

realm = "my-realm"
config = Configuration(
    host="https://my-phasetwo-host/auth/realms",
    access_token=get_access_token(),  # e.g. KeycloakOpenID(...).token(grant_type="client_credentials")["access_token"]
)

with ApiClient(config) as client:
    orgs = OrganizationsApi(client)

    # Create an organization. The new id is in the Location header.
    resp = orgs.create_organization_with_http_info(realm, OrganizationRepresentation(name="example"))
    org_id = resp.headers["Location"].rsplit("/", 1)[-1]

    # Create a link to the IdP Wizard for the organization
    link = orgs.create_portal_link(realm, org_id).link

    # Create and publish an audit event
    EventsApi(client).create_event(
        realm,
        EventRepresentation(type="foo.bar", representation=json.dumps({"orgId": org_id}), time=int(time.time() * 1000)),
    )

Generated code

The API classes and models in phasetwo/openapi are generated from the Phase Two OpenAPI spec by phasetwo-sdk-generator (generator: python) and re-exported from phasetwo. Don't edit them by hand; sdk-generator.json records the spec commit they came from. phasetwo/__init__.py and pyproject.toml are hand-written.

To build: uv build

License

Apache License 2.0, see COPYING.

Metadata

Release files for phasetwo-sdk 0.2.0

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

Source distribution (sdist)

Source distribution for phasetwo-sdk 0.2.0
File Size Uploaded Provenance Actions
phasetwo_sdk-0.2.0.tar.gz 117.1 kB With provenance Details for phasetwo_sdk-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for phasetwo-sdk 0.2.0
File Interpreter ABI Platform Actions
phasetwo_sdk-0.2.0-py3-none-any.whl Python 3 none any Details for phasetwo_sdk-0.2.0-py3-none-any.whl

Total release size: 303.1 kB

Release files / phasetwo_sdk-0.2.0.tar.gz

Download URL phasetwo_sdk-0.2.0.tar.gz
Size 117.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4bbfa85986ee84dde568a59cd723d72586cbe4f026b23110c5d809c5d94219a6
BLAKE2b-256 checksum
How to use checksums
2e978dfb10412edc14ff9b54fbe77e245d9b9c32352ce3a2703c191c915df605
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 13, 2026.

Transparency log

Release files / phasetwo_sdk-0.2.0-py3-none-any.whl

Download URL phasetwo_sdk-0.2.0-py3-none-any.whl
Size 186.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ebcc922b7d4f6336f3a20b251458a417a3445ca0a5de45ac925b1593179aa7e
BLAKE2b-256 checksum
How to use checksums
9c51cf67e9608de4da7a912d8b723cd0f52e177fc8655e2c2deff824ff46fd5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 13, 2026.

Transparency log

Security for phasetwo-sdk 0.2.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for phasetwo_sdk-0.2.0.tar.gz

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 Nov 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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