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

Python
94%
Apache 2.0

SWIRL

Data Engineering · Databases · Search

3,046

Federated AI search and RAG across 100+ enterprise sources—no data extraction, no vector database required.

View details
61
Repo Health
83
Technical
65
Dependency
Built with
Python 94%
Updated 1 weeks ago
Python
97%
MPL 2.0

Taiga Back

Developer Tools · Project Management

859

Self-hosted agile project management backend with Scrum, Kanban, issue tracking, and a full REST API — built on Django and PostgreSQL.

View details
72
Repo Health
74
Technical
64
Dependency
Built with
Python 97%
Updated 1 months ago
C++
75%
Apache 2.0

Timeplus Proton

Analytics · Data Engineering

2,273

Single C++ binary SQL engine for real-time stream processing, ETL, and analytics on Kafka, Redpanda, and ClickHouse with sub-millisecond latency.

View details
87
Repo Health
82
Technical
68
Dependency
Built with
C++ 75%
Python 11%
Updated 2 weeks ago
Python
68%
AGPL 3.0

Tracecat

AI Agents · Automation · Security

3,860

Open-source agentic security automation platform that runs AI agents and durable workflows at scale with sandboxed execution.

View details
89
Repo Health
88
Technical
66
Dependency
Built with
Python 68%
TypeScript 30%
Updated 6 days ago
Python
73%
Apache 2.0

Unsloth

AI Assistants · AI Development

78,493

Run and fine-tune LLMs, diffusion, audio and embedding models on your own hardware, from a native desktop app, a browser UI, or a Python library.

View details
89
Repo Health
83
Technical
70
Dependency
Built with
Python 73%
TypeScript 22%
Updated 6 days ago
Python
96%
AGPL 3.0

VideoHighlighter

Video Editors

296

Local AI desktop tool that scores, explains, and cuts the moments that matter in raw footage — scene, motion, audio, object, and action detection, fully offline via Ollama and Whisper.

View details
83
Repo Health
84
Technical
71
Dependency
Built with
Python 96%
Updated 1 weeks ago
Python
50%
AGPL 3.0

VoiceStudio

Mcp · Music Audio · Voice AI

83,641

Open-source, fully local ElevenLabs alternative for voice cloning, voice design, video dubbing, dictation, transcription and audiobooks, with a local API and MCP server for agents.

View details
86
Repo Health
83
Technical
70
Dependency
Built with
Python 50%
JavaScript 22%
TypeScript 21%
Updated 6 days ago
Python
92%
GPL 3.0

Weblate

Developer Tools

6,124

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 92%
Updated 6 days ago
Python
66%
Apache 2.0

WrenAI

AI Agents · Analytics · Data Engineering

17,958

Open-source GenBI engine that lets AI agents turn natural-language questions into governed SQL, charts, and shareable dashboards across 20+ data sources — no vendor lock-in, no black-box prompts.

View details
91
Repo Health
91
Technical
68
Dependency
Built with
Python 66%
Rust 31%
Updated 1 weeks 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