{"id":5538,"library":"types-pysaml2","title":"Type Stubs for pysaml2","description":"types-pysaml2 provides PEP 561 compliant type stubs for the pysaml2 library, enabling static type checking tools like MyPy to validate code that uses pysaml2. It aims to provide accurate type annotations for the current state of pysaml2. Releases are generally infrequent, driven by bug fixes or significant changes in the underlying pysaml2 library.","status":"active","version":"1.0.2","language":"en","source_language":"en","source_url":"https://github.com/cex-solutions/types-pysaml2","tags":["type-stubs","mypy","pysaml2","saml","static-analysis"],"install":[{"cmd":"pip install types-pysaml2","lang":"bash","label":"Install library"}],"dependencies":[{"reason":"This package provides type stubs for pysaml2; pysaml2 is required for runtime functionality.","package":"pysaml2","optional":false}],"imports":[{"note":"Type stubs are not imported directly; they provide annotations for imports from the 'saml2' package.","symbol":"Config","correct":"from saml2.config import Config"},{"note":"Type stubs are not imported directly; they provide annotations for imports from the 'saml2' package.","symbol":"Saml2Client","correct":"from saml2.client import Saml2Client"},{"note":"Type stubs are not imported directly; they provide annotations for imports from the 'saml2' package.","symbol":"Saml2Response","correct":"from saml2.response import Saml2Response"}],"quickstart":{"code":"import os\nfrom saml2.config import Config\nfrom saml2.client import Saml2Client\n\ndef setup_saml_client(config_file_path: str) -> Saml2Client:\n    config = Config()\n    config.load_file(config_file_path)\n    client = Saml2Client(config)\n    return client\n\n# Example usage (requires an actual saml2 config file)\n# config_path = os.environ.get('SAML2_CONFIG_PATH', 'path/to/saml2/config.xml')\n# if os.path.exists(config_path):\n#     saml_client = setup_saml_client(config_path)\n#     print(f\"SAML2 client created with entity ID: {saml_client.config.entityid}\")\n# else:\n#     print(f\"Warning: SAML2 config file not found at {config_path}. Quickstart not fully runnable without it.\")\n\n# To verify type checking, run mypy on this file after installing types-pysaml2 and pysaml2:\n# pip install mypy pysaml2 types-pysaml2\n# mypy your_script_name.py","lang":"python","description":"This quickstart demonstrates how to use `pysaml2` with the benefits of type checking provided by `types-pysaml2`. Note that `types-pysaml2` itself does not contain runtime code; it merely provides type annotations. To utilize the stubs, you write `pysaml2` code as usual, and `mypy` (or another static type checker) will automatically pick up the annotations provided by `types-pysaml2`."},"warnings":[{"fix":"Install the core library: `pip install pysaml2`.","message":"types-pysaml2 does not contain any runtime code; it only provides type annotations. Ensure you have `pysaml2` installed as the actual runtime library. Without `pysaml2`, `types-pysaml2` serves no functional purpose beyond providing stubs for a non-existent package.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade both `pysaml2` and `types-pysaml2` to their latest compatible versions to ensure the most accurate type hints. Check the `types-pysaml2` changelog for specific compatibility notes.","message":"Type hints might be incorrect or incomplete if the version of `types-pysaml2` does not sufficiently match the installed version of `pysaml2`. While `types-pysaml2` tries to stay current, significant API changes in `pysaml2` might not be immediately reflected.","severity":"gotcha","affected_versions":"all"},{"fix":"Adjust type annotations and unpacking logic for `LogoutResult` to expect 4 elements (`status`, `reason`, `binding`, `relay_state`). For example, change `status, reason, binding = logout_result` to `status, reason, binding, relay_state = logout_result` in your type hints and code.","message":"The type hint for the `LogoutResult` tuple was corrected from 3 to 4 elements in v1.0.2 to accurately reflect `pysaml2`'s actual return signature. Code relying on the `LogoutResult` tuple's length for unpacking might be affected at type-checking time if it expects 3 elements.","severity":"breaking","affected_versions":">=1.0.2"},{"fix":"Update to `types-pysaml2` v1.0.1 or newer to ensure the correct type hint for `Config.context` is applied during static analysis.","message":"In versions prior to v1.0.1, the type hint for `Config.context` was incorrect. It was fixed in v1.0.1 to correctly indicate a string type, aligning with `pysaml2`'s implementation.","severity":"gotcha","affected_versions":"<1.0.1"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}