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-levelprofiles.process_responsetrusts a caller-suppliedverified_signed_idsand 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 --releaseon 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.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pygamlastan-0.5.0.tar.gz | 302.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pygamlastan-0.5.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.5.0.tar.gz
| Download URL | pygamlastan-0.5.0.tar.gz |
|---|---|
| Size | 302.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb41fa93dcc74c71e0a74482c8f8d8a02f5f751c829c023d5a79be5cf86fe643
|
|
BLAKE2b-256 checksum How to use checksums |
570195fd5222a8419504a8700cc4ec240a14a9fd9a958eb7bba380868b62a8f3
|
| 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 4, 2026.
Transparency logRelease files / pygamlastan-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | pygamlastan-0.5.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 |
d15cfdfe98c62db22ebc33fb8bc6a665a3d504dde219b7cabbdabff1bf24470d
|
|
BLAKE2b-256 checksum How to use checksums |
d437a95ed3a77eacf6444170d5e0a7fa29c1d85d41d4c004499be5a828376872
|
| 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 4, 2026.
Transparency log