python3-saml

Add SAML 2.0 single sign-on and single logout to Python applications

Library
PyPI
v1.16.0
755stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
50/100Fair
Development Activity4
Maintenance20
Community88
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
70/100Good
Architecture76
Code Quality74
Innovation66
Learning Curve62

python3-saml turns a Python application into a SAML Service Provider (SP) that can federate authentication with an Identity Provider (IdP), implementing the SAML 2.0 Web Browser SSO Profile including SP-initiated and IdP-initiated SSO and SLO (Single Logout). It handles assertion/nameID encryption, message and assertion signature validation, and SP metadata publishing.

The library is session-less by design — it validates and parses SAML messages but delegates actual session management to the host application, and it ships as onelogin/saml2 (the module namespace retained from its predecessor python-saml), with reference demo integrations for Django, Flask, Pyramid, and Tornado. It depends on xmlsec and lxml for XML signature verification and encryption, and defusedxml/careful XML parsing to defend against XXE and XML-signature-wrapping attacks, several of which were the subject of past published CVEs the project has since patched.

What You Get

  • An Auth class (onelogin.saml2.auth) providing high- and low-level APIs for processing SSO/SLO requests and responses
  • Assertion and NameID encryption/decryption plus signature validation for AuthNRequest, LogoutRequest, and LogoutResponse messages
  • SP metadata generation, including signed metadata support
  • Reference demo integrations for Django, Flask, Pyramid, and Tornado showing end-to-end wiring
  • Security utilities (get_last_request_id, get_last_message_id, get_last_assertion_id) for replay-attack prevention

Common Use Cases

  • Adding enterprise SSO login to a Django, Flask, or Pyramid app so employees authenticate via their company’s IdP (Okta, Azure AD, ADFS)
  • Implementing centralized single logout (SLO) across multiple SP applications sharing one IdP session
  • Publishing signed SP metadata for automated IdP-side SAML configuration in enterprise B2B integrations
  • Building a custom identity broker or SSO gateway that needs to validate and reissue SAML assertions

Under The Hood

Architecture - The core lives in src/onelogin/saml2/: auth.py is the main entry point coordinating request/response flow, settings.py loads SP/IdP configuration (certs, endpoints, security options), authn_request.py/logout_request.py/logout_response.py build outgoing SAML XML messages, response.py parses and validates incoming assertions, metadata.py generates SP metadata XML, and xml_utils.py/xmlparser.py/utils.py centralize XML signing, canonicalization, and signature-wrapping defenses shared across all message types. idp_metadata_parser.py additionally lets an SP bootstrap its IdP configuration directly from a published IdP metadata XML document.

Tech Stack - Python 3.7+, built on xmlsec (Python bindings to the XML Security Library) for XML-DSig/XML-Enc operations, lxml for XML parsing, and isodate for SAML’s ISO-8601 timestamps. The README explicitly warns against installing lxml from binary wheels to avoid libxml2 version mismatches with xmlsec, reflecting the security-sensitive nature of correct XML-crypto library pairing.

Code Quality - Six top-level test modules exercise SSO/SLO flows, signature validation, and metadata generation, with Coveralls-tracked coverage and a GitHub Actions CI workflow. The project’s README maintains an unusually detailed changelog of security fixes by version (CVE-2017-11427, CVE-2017-9672, CVE-2016-1000251), documenting exactly which historical versions were vulnerable to XXE, signature-wrapping, and validation-bypass attacks — a strong signal of security-conscious maintenance for a protocol library where correctness is a security property.

API Design - Auth exposes both a high-level API (call process_response()/process_slo() and check is_authenticated()) for common flows and lower-level building blocks for custom SAML handling, but the library is explicit that strict mode MUST be enabled in production and that IdP certificates should be registered directly rather than relying on the more collision-prone fingerprint method — meaning safe usage requires reading the security-guidelines section, not just the quickstart.

Used by 6 apps in this directory

Python
90%
Apache 2.0

Apache Airflow

Data Engineering

46,530

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
66
Dependency
Built with
Python90%
Updated today
C++
66%
Other

Memgraph

Databases · AI Development

4,347

High-performance in-memory graph database for AI context and real-time analytics

View details
90
Repo Health
79
Technical
70
Dependency
Built with
C++66%
Python18%
Updated today
TypeScript
55%
Other

OpenReplay

Analytics

12,525

Self-hosted session replay and product analytics suite that lets you see exactly what users do on your web app — without sending data to third parties.

View details
91
Repo Health
77
Technical
72
Dependency
Built with
TypeScript55%
Go12%
Python10%
Updated yesterday
Python
55%
Other

PostHog

Analytics · Monitoring · Developer Tools

37,777

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
67
Dependency
Built with
Python55%
TypeScript36%
Updated today
Python
58%
Other

Sentry

Security · Developer Tools · Monitoring

44,574

Developer-first error tracking and performance monitoring platform with AI-powered root-cause analysis across 20+ languages and frameworks.

View details
95
Repo Health
80
Technical
70
Dependency
Built with
Python58%
TypeScript41%
Updated today
Python
91%
GPL 3.0

Weblate

Developer Tools

6,028

Continuous localization platform that commits translations directly into your version control system with full translator attribution.

View details
95
Repo Health
86
Technical
74
Dependency
Built with
Python91%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search