skillfed

asn1

Python-ASN1 is a simple ASN.1 encoder and decoder for Python 2.7+ and 3.5+.

asn1 v3.3.0 1.7M downloads/30d#3,595 on PyPI110
Permissive license MIT Active released

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 asn1

uv

uv add asn1

poetry

poetry add asn1

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: Microsoft :: WindowsOperating System :: POSIXOperating System :: UnixProgramming Language :: PythonProgramming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Utilities

Tags

ASN.1 encoder decoderBER DER encodingASN.1 serializationbinary data encodingASN.1 REAL typeobject identifier encodingASN.1 parser
asn1-encodingprotocol-parsingbinary-serialization

More Utilities packages