python3-saml

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

Library
PyPI
v1.16.0
758 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
49 /100 Fair
Development Activity 0
Maintenance 20
Community 88
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
70 /100 Good
Architecture 76
Code Quality 74
Innovation 66
Learning Curve 62

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
89%
Apache 2.0

Apache Airflow

Data Engineering

46,995

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
64
Dependency
Built with
Python 89%
Updated 4 days ago
C++
66%
Other

Memgraph

AI Development · Databases

4,581

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

View details
90
Repo Health
79
Technical
69
Dependency
Built with
C++ 66%
Python 18%
Updated 5 days ago
TypeScript
55%
Other

OpenReplay

Analytics

12,911

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
90
Repo Health
77
Technical
66
Dependency
Built with
TypeScript 55%
Go 13%
Updated 1 weeks ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

39,975

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
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 4 days ago
Python
57%
Other

Sentry

Analytics · Developer Tools · Monitoring

44,862

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
69
Dependency
Built with
Python 57%
TypeScript 41%
Updated 4 days ago
Python
91%
GPL 3.0

Weblate

Developer Tools

6,094

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

View details
95
Repo Health
86
Technical
67
Dependency
Built with
Python 91%
Updated 4 days ago

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