gnupg
A Python wrapper for GnuPG
What it is and what it does
gnupg is a Python wrapper around the GnuPG command-line tool, allowing you to perform cryptographic operations—key generation, encryption, decryption, and signing—from Python code. It is a rewrite of an earlier library that fixed shell injection vulnerabilities caused by unsanitized subprocess calls.
The package provides a GPG class that manages a local keyring and communicates with the GnuPG binary via subprocess. You instantiate it with paths to your keyring files and GnuPG binary, then call methods like gen_key(), encrypt(), and decrypt() to perform operations. It has no runtime Python dependencies but requires GnuPG to be installed on the system.
Use it for:
- Automate GPG key generation and management in Python applications without manual shell scripting.
- Encrypt sensitive data in a Python service before storage or transmission.
- Decrypt files or messages signed by external parties as part of a larger workflow.
- Build a Python-based key distribution system that relies on GPG trust models.
- Integrate GPG operations into CI/CD pipelines or batch processing jobs.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A Python wrapper around GnuPG that lets you generate keys, encrypt, and decrypt messages programmatically, with patches for shell injection vulnerabilities.
Yes, with conditions. The package is stable and in the top 5000 PyPI downloads, with no known vulnerabilities. However, it is dormant—last release was 2017-09-06—so it may not support modern Python versions or recent GnuPG features. Install it if you need GPG integration in a Python 2 or early Python 3 codebase and can tolerate lack of active maintenance.
Install
gnupg on PyPI
pip
pip install gnupguv
uv add gnupgpoetry
poetry add gnupgInstalling gnupg
Before you install
High install friction: no runtime dependencies but requires a working GnuPG binary on the system. Maintenance is dormant—last release was 2017-09-06, over 3264 days ago, though the repository remains active with a recent commit on 2024-08-01.
License in practice
Licensed under GPLv3+, a copyleft license. Any application that links this library must also be distributed under a compatible open-source license or obtain an exception.
Quickstart
pip install gnupg
from gnupg import GPG
gpg = GPG(binary='/usr/bin/gpg', homedir='./keys')
message = "test"
encrypted = str(gpg.encrypt(message, recipient_key_id))
decrypted = str(gpg.decrypt(encrypted))
GnuPG binary must be installed and accessible on the system (e.g., /usr/bin/gpg on Linux/macOS).
Verify before relying
- Whether patches for shell injection vulnerabilities cover all supported Python versions.
- Current compatibility with modern GnuPG versions and Python 3.x releases beyond 3.4.
- Whether dormant maintenance affects security patches or bug fixes going forward.
Package facts
| License | GPLv3+ (copyleft) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | dormant — 3,264 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,074,211/month — #3,318 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: gnupg-2.3.1-py2.7.egg; gnupg-2.3.1-py3.4.egg; gnupg-2.3.1.tar.gz
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
PGPyPGPy implements OpenPGP (RFC 4880) in pure…
permissive · top 5,000 on PyPI
python-gnupgProvides Python bindings to GnuPG for key…
permissive · top 5,000 on PyPI
PGPy13PGPy13 is a Python library for OpenPGP…
permissive · top 15,000 on PyPI
pysequoiaPySequoia provides OpenPGP encryption,…
permissive · top 15,000 on PyPI
cryptoProvides command-line tools to encrypt and…
permissive · top 5,000 on PyPI
sopsySOPSy wraps the SOPS command-line tool to…
permissive · top 15,000 on PyPI
eciespyEncrypts and decrypts data using Elliptic Curve…
permissive · top 15,000 on PyPI
pyragepyrage provides Python bindings to the Rust…
permissive · top 15,000 on PyPI
pyAesCryptEncrypts and decrypts files and binary streams…
permissive · top 15,000 on PyPI
pyscryptA pure-Python implementation of the scrypt…
permissive · top 15,000 on PyPI