cryptography

The standard cryptographic library for Python, pairing safe high-level recipes with low-level primitives backed by Rust and OpenSSL.

Library
PyPI
v50.0.2
7,821 stars
Apache-2.0 OR BSD-3-Clause

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
84 /100 Excellent
Development Activity 100
Maintenance 52
Community 84
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
91 /100 Excellent
Architecture 88
Code Quality 95
Innovation 90
Learning Curve 90

cryptography is the standard cryptographic library for Python, providing both safe, high-level recipes and low-level primitives for developers who need fine-grained control. Its Fernet class offers authenticated symmetric encryption with sane defaults out of the box, while the hazmat (“hazardous materials”) layer exposes ciphers, hashes, KDFs, and asymmetric algorithms for building custom protocols — clearly separated so casual users don’t accidentally reach for unsafe building blocks.

Under the hood, nearly all cryptographic operations are implemented in a Rust workspace (cryptography-openssl, cryptography-key-parsing, cryptography-x509, cryptography-x509-verification) that wraps OpenSSL, BoringSSL, or AWS-LC and is exposed to Python through PyO3/maturin bindings. This design replaced most of the historical hand-written CFFI bindings, improving memory safety, while shipping prebuilt wheels for every major platform so most users never need a Rust or C toolchain to install it.

What You Get

  • Fernet high-level symmetric encryption recipe with built-in key rotation via MultiFernet
  • A hazmat primitives layer covering ciphers, hashes, HMAC/CMAC, AEAD, and KDFs for custom protocol design
  • Full asymmetric crypto support: RSA, DSA, ECDSA/ECDH, Ed25519/Ed448, and X25519/X448
  • An X.509 toolkit for parsing, building, and verifying certificates and CSRs, backed by a dedicated Rust verification engine
  • Prebuilt wheels for every major platform so consumers never need a local Rust or OpenSSL toolchain

Common Use Cases

  • Encrypting stored secrets, tokens, or session data with an authenticated symmetric cipher
  • Parsing, validating, and building X.509 certificate chains for TLS/PKI tooling
  • Signing and verifying payloads or webhooks with asymmetric keys
  • Composing low-level primitives such as AES-GCM and HKDF to implement custom secure protocols

Under The Hood

Architecture

cryptography splits into a Python-facing package (src/cryptography) and a Rust core (src/rust) compiled via PyO3/maturin and exposed through hazmat.bindings._rust. The Python layer has two tiers: a friendly “recipes” layer (fernet.py, the high-level x509 API) and the hazmat (“hazardous materials”) layer exposing low-level primitives (hazmat/primitives, hazmat/backends/openssl, hazmat/bindings). The Rust workspace is itself modularized into focused crates — cryptography-cffi (the PyO3/CFFI bridge), cryptography-crypto (constant-time ops, PKCS12/PBKDF1 helpers), cryptography-key-parsing (ASN.1/PKCS8/SPKI/RSA/DSA/EC parsing), cryptography-openssl (safe Rust wrappers over OpenSSL’s C API), and cryptography-x509 / cryptography-x509-verification (a from-scratch Rust X.509 chain-building and verification engine). Because nearly every primitive is implemented in Rust and merely exposed to Python as thin wrapper calls, changing the core OpenSSL binding surface ripples through ciphers, hashes, and asymmetric keys alike.

Tech Stack

The build system is maturin (PyO3-based), combining Rust and Python in one wheel, configured via pyproject.toml plus Cargo.toml/Cargo.lock. The Python side depends on cffi for legacy platforms and typing-extensions for pre-3.11 interpreters. The Rust workspace links against OpenSSL by default, with dedicated CI workflows (boring-open-awslc-bump.yml) that build and test against BoringSSL and AWS-LC as alternate backends. Development tooling is orchestrated through nox (noxfile.py) driving pytest, pytest-xdist, pytest-randomly, and pytest-benchmark, with ruff/black for linting and Sphinx for documentation. Distribution ships as prebuilt, per-platform wheels via a dedicated wheel-builder.yml workflow, so most consumers install without a local Rust or C toolchain.

Code Quality

The test suite is extensive, spanning hundreds of test files under tests/hazmat and tests/x509, plus an embedded Wycheproof test-vector suite (tests/wycheproof) for cross-implementation cryptographic correctness and a bench/ directory for performance regression tracking via pytest-benchmark. Type hints and from __future__ import annotations are used throughout, with a py.typed marker signaling first-class typing support. CI (ci.yml) runs across multiple OS and Python versions plus alternate OpenSSL-compatible backends, and errors are surfaced through explicit typed exceptions (InvalidSignature, InvalidToken) rather than swallowed silently.

API Design The high-level Fernet API is deliberately minimal — generate_key, encrypt, and decrypt — intentionally hiding cipher-mode and IV choices to prevent misuse, while the hazmat namespace is explicitly named and documented as “hazardous materials” to warn developers away from low-level primitives unless they specifically need them. Constructors compose consistently (Cipher, algorithms, and modes combine as orthogonal building blocks), and typed exceptions communicate failure clearly. Getting started requires almost no boilerplate for the common case (Fernet(key).encrypt(...)), while low-level usage requires deliberately assembling primitives by hand — a safety-first design choice rather than an oversight.

Used by 54 apps in this directory

TypeScript
50%
Other

Phase Console

Devops · Security

931

End-to-end encrypted secrets management for engineering teams — from local dev to Kubernetes production.

View details
85
Repo Health
73
Technical
63
Dependency
Built with
TypeScript 50%
Python 48%
Updated 1 weeks ago
Python
62%
Apache 2.0

Polar

Developer Tools · Ecommerce · Invoicing Finance

10,410

Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.

View details
90
Repo Health
82
Technical
66
Dependency
Built with
Python 62%
TypeScript 31%
Updated 1 weeks ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

40,397

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 6 days ago
Python
99%
Apache 2.0

Rasa Open Source

AI Assistants · AI Development · Voice AI

21,353

Rasa Open Source is a Python machine learning framework for building contextual, multi-turn chatbots and voice assistants that understand natural language and maintain conversation state.

View details
62
Repo Health
78
Technical
63
Dependency
Built with
Python 99%
Updated 3 months ago
Python
45%
Other

Redash

Analytics · Data Engineering

28,849

Redash lets anyone connect to 35+ SQL and NoSQL data sources, write a query in the browser, and turn the result into a shared dashboard — no separate BI suite required.

View details
91
Repo Health
74
Technical
61
Dependency
Built with
Python 45%
JavaScript 29%
TypeScript 19%
Updated 1 weeks ago
Python
57%
Other

Sentry

Analytics · Developer Tools · Monitoring

45,632

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
66
Dependency
Built with
Python 57%
TypeScript 42%
Updated 6 days ago
Python
64%
AGPL 3.0

Shadowbroker

Analytics · Monitoring · Security

11,358

Self-hosted OSINT dashboard that fuses 60+ live intelligence feeds — flight tracking, ship AIS, satellites, CCTV, seismic and radio networks — into one real-time map, with an agent-ready command channel for AI co-analysts.

View details
85
Repo Health
83
Technical
71
Dependency
Built with
Python 64%
TypeScript 32%
Updated 1 weeks ago
Python
79%
AGPL 3.0

Skyvern

AI Agents · Automation

23,257

Skyvern (YC S2023) automates browser-based workflows by pairing LLMs with computer vision, letting agents click, fill, and extract data on sites they've never seen, without brittle XPath selectors that break on every layout change.

View details
89
Repo Health
82
Technical
70
Dependency
Built with
Python 79%
TypeScript 19%
Updated 6 days ago
HTML
66%
AGPL 3.0

ST3GG

Developer Tools · Security

1,832

The ultimate open-source steganography suite — hide anything in any file using 100+ encoding techniques, detect it all, and run everything 100% in your browser.

View details
38
Repo Health
74
Technical
72
Dependency
Built with
HTML 66%
Python 31%
Updated 4 months 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