Skip to main content

Python bindings for the gamlastan SAML 2.0 library

Project description

pygamlastan

Python bindings for gamlastan 0.5.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

from pygamlastan import xml, profiles, security, crypto

# Verify the response signature with the trusted IdP certificate.
verifier = crypto.SamlVerifier.from_cert(idp_cert_pem)
verified = verifier.verify_enveloped(response_xml)

parsed = xml.parse_response(response_xml)
result = profiles.process_response(
    parsed,
    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",
    verified_signed_ids=verified.signed_reference_ids(),
    replay_cache=security.InMemoryReplayCache(),
)
print(result.name_id, result.attributes_dict())

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygamlastan-0.1.1.tar.gz (144.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygamlastan-0.1.1-cp310-abi3-manylinux_2_28_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

File details

Details for the file pygamlastan-0.1.1.tar.gz.

File metadata

  • Download URL: pygamlastan-0.1.1.tar.gz
  • Upload date:
  • Size: 144.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pygamlastan-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d8bd64b3fc4756e660550f6069c381e68de5dacde48ac839ac1d8b3fddd48846
MD5 251cbd9c9528dcbe9e88cbf481f965cd
BLAKE2b-256 f986b223b47fff28391422a56438ec7613c10b43b14ca1aea20afefe99d93637

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygamlastan-0.1.1.tar.gz:

Publisher: release.yml on kushaldas/pygamlastan

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygamlastan-0.1.1-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pygamlastan-0.1.1-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eb1e72ffec4eccc9d1698a4078517f6ae4a3fa4ab02a1ea5acb67010ba44085e
MD5 405cb7f9bfb1a706a7e8ee01e793bdd5
BLAKE2b-256 66f27b1ce46af20746c8e0af557b93ebe5b3b85acd6cbce7be4da975a2fcae42

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygamlastan-0.1.1-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: release.yml on kushaldas/pygamlastan

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page