Skip to main content

pygamlastan

Python bindings for gamlastan 0.9.x, a pure-Rust SAML 2.0 library - types, XML, crypto, metadata, bindings, security, and profiles. Built with PyO3 0.29 + maturin (abi3, Python ≥ 3.10).

The binding mirrors gamlastan's modules as Python submodules: pygamlastan.{core, xml, crypto, bindings, metadata, security, profiles, attribute_map, idp, logout}. Parsing converts gamlastan's zero-copy *Ref views to owned values at the FFI boundary, so no Rust lifetime escapes into Python.

Example - SP processes an IdP response

process_response_verified is the safe entry point: it verifies the XML-DSig internally over the exact bytes it validates, so signature trust cannot drift from the assertion you consume. Inbound XML is parsed through a hardened path that rejects DTDs (no XXE) and bounds entity expansion.

from pygamlastan import profiles, security, crypto

verifier = crypto.SamlVerifier.from_cert(idp_cert_pem)   # trusted IdP cert

result = profiles.process_response_verified(
    response_xml,                       # raw bytes as received at the ACS
    verifier,
    security.SecurityConfig(),          # production defaults
    sp_entity_id="https://sp.example.org/sp",
    acs_url="https://sp.example.org/acs",
    expected_idp_entity_id="https://idp.example.org",
    expected_request_id="_req123",
    replay_cache=security.InMemoryReplayCache(),
)
print(result.name_id, result.attributes_dict())

Security: prefer process_response_verified. The lower-level profiles.process_response trusts a caller-supplied verified_signed_ids and does not verify signatures itself - passing that without a real verification is an authentication bypass. See the security guide.

Gamlastan 0.9 APIs

The 0.5 release exposes gamlastan 0.9's algorithm allowlists, replay-aware LogoutRequest validation, participant-bound IdP session/logout helpers, recipient-bound artifact-store contract, and explicit unsolicited-SSO policy. Worked examples are in the signing, IdP integration, SP integration, and bindings guides.

HSM / PKCS#11 signing

from pygamlastan import crypto

prov = crypto.Pkcs11Provider("/usr/lib/softhsm/libsofthsm2.so")
session = prov.open_session("1234")
signer = crypto.SamlSigner.with_pkcs11(session.signer("saml-signing-key", "rsa-sha256"))
signed = signer.sign_enveloped(xml_with_signature_template)

Deploying with an HSM? Prefer building the wheel in - or against - your target environment instead of relying on the generic prebuilt wheel. The compiled extension links the host's C/crypto stack, and your PKCS#11 module (SoftHSM2, kryoptic, or a vendor driver) is dlopen-ed at runtime from that same host. Building where your token tooling and system libraries live (e.g. maturin build --release on the target host or a container matching production) avoids glibc/loader and provider-ABI mismatches and lets you validate signing against the real module before shipping.

Development

uv venv
uv pip install --python .venv/bin/python maturin
VIRTUAL_ENV=$PWD/.venv .venv/bin/maturin develop --uv
.venv/bin/python -m pytest tests/

The PKCS#11 test self-skips unless SoftHSM2 (softhsm2-util + pkcs11-tool) is installed; when present it provisions a throwaway token and signs for real.

Documentation

You can read the latest or the documentation (Sphinx 9.1) lives in docs/: installation, a quickstart, task guides (SP/IdP integration, signing & HSM, bindings, metadata, attributes, validation), and a per-module API reference. Build it with the project venv so the package is importable:

uv pip install --python .venv/bin/python --group docs
.venv/bin/python -m sphinx -b html docs docs/_build/html
# open docs/_build/html/index.html

Type stubs

The package ships PEP 561 type information: py.typed plus one .pyi per submodule, living in python/pygamlastan/ (a maturin mixed Rust+Python layout where the compiled extension is pygamlastan._native). The stubs are included in the wheel, so mypy / pyright pick them up with no extra configuration.

Release files for pygamlastan 0.6.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 pygamlastan 0.6.0
File Size Uploaded
pygamlastan-0.6.0.tar.gz 307.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pygamlastan 0.6.0
File Interpreter ABI Platform
pygamlastan-0.6.0-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details

Total release size: 3.8 MB

Release files / pygamlastan-0.6.0.tar.gz

Download URL pygamlastan-0.6.0.tar.gz
Size 307.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e3d9a3c89cbeef97c34fb299ea3fdace591c583ab5f2ea9562da89e2b1d2a367
BLAKE2b-256 checksum
How to use checksums
4e8a32023f630e5c29a876b7e482ede7dd0f3426b2d7c4a3ed43a45131f8867f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 14, 2026.

Transparency log

Release files / pygamlastan-0.6.0-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL pygamlastan-0.6.0-cp310-abi3-manylinux_2_28_x86_64.whl
Size 3.5 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
3a32fd0522f91bda3a6036c9e58814731abc514afaa97dfc8dcf9df349841c2a
BLAKE2b-256 checksum
How to use checksums
3e92566137ffa1eebf312dc69be16077dcd4226d2c89b2d0f520204b01feccdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.3.0

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