pygamlastan
Python bindings for gamlastan 0.7.0, 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}. 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.
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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pygamlastan-0.3.0.tar.gz.
File metadata
- Download URL: pygamlastan-0.3.0.tar.gz
- Upload date:
- Size: 228.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
623223e67779118e473d2a4e8c87cbaa04b963a88bfa63fc16349db70dcbab4f
|
|
| MD5 |
5781998a1c7da53277b23d1ec0084bcb
|
|
| BLAKE2b-256 |
e7b74957f7cbf19829e1786f018115cc1d13a28f482ca31f8086d46478ab2ddf
|
Provenance
The following attestation bundles were made for pygamlastan-0.3.0.tar.gz:
Publisher:
release.yml on kushaldas/pygamlastan
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygamlastan-0.3.0.tar.gz -
Subject digest:
623223e67779118e473d2a4e8c87cbaa04b963a88bfa63fc16349db70dcbab4f - Sigstore transparency entry: 2102142426
- Sigstore integration time:
-
Permalink:
kushaldas/pygamlastan@a4d0e2274edc42eb2b7adc2f11aaedff2d49139a -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/kushaldas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a4d0e2274edc42eb2b7adc2f11aaedff2d49139a -
Trigger Event:
push
-
Statement type:
File details
Details for the file pygamlastan-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pygamlastan-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd0d140d5bd9271d60ca30da5e0fb4be1405d72082a7272745e69021a9df3922
|
|
| MD5 |
d501a881f61a8129837adae425366343
|
|
| BLAKE2b-256 |
58fd3255059c9004609461f1b226eae26bccc342c9d34a042af4e81a3a3848e1
|
Provenance
The following attestation bundles were made for pygamlastan-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl:
Publisher:
release.yml on kushaldas/pygamlastan
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygamlastan-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
dd0d140d5bd9271d60ca30da5e0fb4be1405d72082a7272745e69021a9df3922 - Sigstore transparency entry: 2102142528
- Sigstore integration time:
-
Permalink:
kushaldas/pygamlastan@a4d0e2274edc42eb2b7adc2f11aaedff2d49139a -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/kushaldas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a4d0e2274edc42eb2b7adc2f11aaedff2d49139a -
Trigger Event:
push
-
Statement type: