M2Crypto
A Python crypto and SSL toolkit
What it is and what it does
M2Crypto is a Python wrapper around OpenSSL that exposes cryptographic operations and TLS functionality through a high-level API. It provides RSA, DSA, DH key generation and operations, symmetric ciphers (including AES), HMAC and message digest functions, and full TLS client/server implementation. It also extends Python's standard httplib, urllib, and xmlrpclib with HTTPS support, and includes S/MIME v2 messaging and FTP/TLS capabilities.
The library has been in maintenance mode since 2014 and is actively maintained but explicitly recommended only for existing applications. The maintainer directs new projects toward more modern alternatives. M2Crypto depends only on packaging at runtime and requires OpenSSL headers and a C compiler to install; prebuilt wheels exist for recent Python versions on Windows.
Use it for:
- Migrate legacy Python applications that already use M2Crypto for TLS and cryptographic operations without rewriting.
- Implement HTTPS clients or servers when you need direct OpenSSL control and already have M2Crypto in your codebase.
- Add HMAC-based session management (AuthCookies) to web applications requiring unforgeable authentication tokens.
- Perform RSA or DSA key generation and cryptographic operations in systems where OpenSSL interoperability is critical.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
M2Crypto wraps OpenSSL via SWIG to provide Python access to cryptographic primitives (RSA, DSA, AES, HMAC), TLS client/server implementation, and HTTPS extensions.
Yes, but with conditions. Install M2Crypto only if you are maintaining existing code that already depends on it or if you need direct OpenSSL interoperability that modern alternatives do not provide. Do not use it for new projects—the maintainer explicitly recommends alternatives instead. Medium install friction (compiled extension) is acceptable for established deployments. No known vulnerabilities and permissive licensing support continued use.
Install
m2crypto on PyPI
pip
pip install m2cryptouv
uv add m2cryptopoetry
poetry add m2cryptoInstalling M2Crypto
Before you install
Medium install friction due to compiled C extension requiring OpenSSL headers and build tools. Active maintenance with recent release (83 days old), though explicitly in maintenance mode since 2014—suitable for existing deployments but new projects should consider alternatives.
License in practice
BSD-2-Clause is permissive; you may use, modify, and distribute M2Crypto freely in commercial and private projects with minimal restrictions.
Quickstart
pip install m2crypto
from M2Crypto import BIO, RSA
key = RSA.gen_key()
Requires OpenSSL development headers and a C compiler; on Windows prebuilt wheels are available for Python 3.10–3.14.
Verify before relying
- Whether the library's documented memory-leak caveats and lack of key-clearing features pose practical risks for your use case.
- Current state of the SWIG bindings and whether all OpenSSL features you need are exposed.
- Specific key generation parameters and their defaults for RSA and DSA operations.
Package facts
| License | BSD-2-Clause (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 1 — packaging |
| Maintenance | actively maintained — 83 days since the last release |
| First released | |
| Downloads | 263,997/month — #8,346 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: m2crypto-0.48.0-cp310-cp310-win_amd64.whl; m2crypto-0.48.0-cp311-cp311-win_amd64.whl; m2crypto-0.48.0-cp312-cp312-win_amd64.whl; m2crypto-0.48.0-cp313-cp313-win_amd64.whl; m2crypto-0.48.0-cp314-cp314-win_amd64.whl
Keywords: cryptography, openssl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
oscryptooscrypto provides TLS sockets, key generation,…
permissive · top 1,000 on PyPI
tlslite-ngPure Python implementation of SSL/TLS protocols…
copyleft · top 15,000 on PyPI
pyOpenSSLpyOpenSSL wraps OpenSSL's SSL/TLS functionality…
permissive · top 1,000 on PyPI
nasslnassl is an OpenSSL wrapper for Python that…
agpl · top 15,000 on PyPI
sslcryptoProvides AES, ECIES, and ECDSA cryptographic…
unclear · top 15,000 on PyPI
sshpubkeysParses and validates OpenSSH public keys,…
permissive · top 5,000 on PyPI
cryptgcryptg provides a native Python extension that…
permissive · top 15,000 on PyPI
python3-dtlsAdds DTLS (Datagram Transport Layer Security)…
permissive · top 15,000 on PyPI
asn1cryptoA pure Python library for parsing and…
permissive · top 1,000 on PyPI
PyKCS11PyKCS11 provides a Python wrapper around the…
copyleft · top 15,000 on PyPI