Skip to main content

Phase Two Python SDK

PyPI 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.1

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.1
File Size Uploaded Provenance Actions
phasetwo_sdk-0.2.1.tar.gz 117.3 kB With provenance Details for phasetwo_sdk-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 303.3 kB

Release files / phasetwo_sdk-0.2.1.tar.gz

Download URL phasetwo_sdk-0.2.1.tar.gz
Size 117.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0f54f93d90d180811b40580ed7d517e44e20aefefcc501cb2411a661fc84239f
BLAKE2b-256 checksum
How to use checksums
9e5bd8cd7f37f04f1c4706c1e2cec0c3b62183383ffc23e3a5f07cb582d9fb1b
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.1-py3-none-any.whl

Download URL phasetwo_sdk-0.2.1-py3-none-any.whl
Size 186.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a0f5d89ef859230830b6b7cce91a11b5acfd9eadf86ce190269ba10da1a9e4b
BLAKE2b-256 checksum
How to use checksums
ace0cd1d1cc17368c16c338608f35ac328a396350fd32ef279b44e675a7df3a0
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.1

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.1.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