asn1
Python-ASN1 is a simple ASN.1 encoder and decoder for Python 2.7+ and 3.5+.
What it is and what it does
Python-ASN1 is a pure-Python library for encoding and decoding ASN.1 data structures, the standard format used in cryptography, network protocols, and structured data interchange. It supports both BER (parser) and DER (parser and generator) encoding formats, including indefinite lengths, and handles most common ASN.1 types including REAL values. The library is designed to be lightweight and portable—it can be integrated by simply including a file in your project or installed via pip.
The package provides two main interfaces: an Encoder class for converting Python data into ASN.1 binary format, and a Decoder class for parsing ASN.1 bytes back into readable values. Recent versions add context-manager support for cleaner resource handling and comply with ASN.1:2008 standards. It targets Python 2.7 and 3.5 through 3.14, relying only on enum-compat as a runtime dependency.
Use it for:
- Encode and decode structured data in network protocols that use ASN.1 serialization
- Work with Object Identifiers (OIDs) and other ASN.1 primitives in protocol implementations
- Integrate ASN.1 handling into legacy Python 2.7 systems without external C dependencies
- Parse and generate ASN.1-encoded messages in compliance testing or protocol analysis
- Build tools that transform ASN.1-encoded data across different encoding formats
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Encodes and decodes ASN.1 data structures using BER and DER formats, supporting most common ASN.1 types including REAL, with a pure-Python implementation.
Yes. The package is actively maintained, has no known vulnerabilities, carries a permissive MIT license, and installs with minimal friction. It is suitable for any project needing ASN.1 encoding/decoding in pure Python across a wide range of Python versions.
Install
asn1 on PyPI
pip
pip install asn1uv
uv add asn1poetry
poetry add asn1Installing asn1
Before you install
Low install friction with a single pure-Python runtime dependency (enum-compat). Actively maintained with a recent release and no known vulnerabilities.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and proprietary projects with minimal obligations.
Quickstart
pip install asn1
import asn1
encoder = asn1.Encoder()
encoder.start()
encoder.write('1.2.3', asn1.Numbers.ObjectIdentifier)
encoded_bytes = encoder.output()
decoder = asn1.Decoder()
decoder.start(encoded_bytes)
tag, value = decoder.read()
Verify before relying
- Whether enum-compat is available for all supported Python versions (2.7, 3.5–3.14)
- Performance characteristics when encoding/decoding large or deeply nested structures
- Use in certificate and cryptographic applications beyond what the fact sheet documents
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — enum-compat |
| Maintenance | actively maintained — 91 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,747,756/month — #3,595 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: asn1-3.3.0-py2.py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
asn1toolsParses, encodes, and decodes ASN.1 messages…
permissive · top 15,000 on PyPI
pyasn1Pyasn1 encodes and decodes ASN.1 data…
permissive · top 100 on PyPI
x690Encodes and decodes data using the X.690 BER…
permissive · top 15,000 on PyPI
asn1cryptoA pure Python library for parsing and…
permissive · top 1,000 on PyPI
bencode.pyEncodes and decodes bencode format, the binary…
unclear · top 15,000 on PyPI
types-pyasn1Provides type stubs for the pyasn1 package,…
permissive · top 5,000 on PyPI
json-numpyProvides lossless JSON encoding and decoding…
permissive · top 15,000 on PyPI
mutf8Encodes and decodes MUTF-8 (Modified UTF-8), a…
permissive · top 5,000 on PyPI
py-multibaseEncodes and decodes data using the Multibase…
permissive · top 15,000 on PyPI
databento-dbndatabento-dbn provides Python bindings for…
permissive · top 5,000 on PyPI