Install & Compatibility
Where this runs
tested against v0.6.0.20260724 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
univ
✓ from pyasn1-stubs.type import univ
✗ from pyasn1-stubs.type import univ
This quickstart demonstrates how to define an ASN.1 `SEQUENCE` type, create an instance, populate it with data, and then encode and decode it using `pyasn1`. The `types-pyasn1` package ensures that static type checkers can validate the usage of `pyasn1` types and methods, catching potential type mismatches or incorrect attribute access at design time.
from pyasn1.type import univ, namedtype
from pyasn1.codec.der import encoder, decoder
# Define an ASN.1 structure (Record) using pyasn1 types
class Record(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('id', univ.Integer()),
namedtype.OptionalNamedType('name', univ.OctetString())
)
# Create an instance and set values
record = Record()
record['id'] = 123 # Type checkers will ensure 'id' is an Integer
record['name'] = univ.OctetString('Example Name') # Type checkers will ensure 'name' is an OctetString
# Encode to DER
encoded_data = encoder.encode(record)
print(f"Encoded: {encoded_data.hex()}")
# Decode from DER (asn1Spec provides the expected type for decoding)
decoded_record, rest = decoder.decode(encoded_data, asn1Spec=Record())
print(f"Decoded ID: {decoded_record['id']}")
print(f"Decoded Name: {decoded_record['name']}")
# Example of type checking: if 'id' was assigned a string, a type checker would flag it.
# For instance, 'record['id'] = "not_an_int"' would cause a type error.
Debug
Known issues
gotchaThe `types-pyasn1` package provides type annotations for a specific version range of `pyasn1` (currently `0.6.*`). Using it with a significantly different version of the runtime `pyasn1` library may lead to inaccurate type checking results or false positives/negatives.fixEnsure that your installed `pyasn1` version is compatible with the `types-pyasn1` version. The `types-pyasn1` version usually aligns its major/minor components with the targeted `pyasn1` version.
affects: <0.6.0 || >0.6.99
gotchaThis is a 'stub-only' package, meaning it contains only type hint files (`.pyi`) and no runtime Python code. You must install the actual `pyasn1` library separately for your code to execute. `types-pyasn1` is only for static analysis.fixInstall `pyasn1` alongside `types-pyasn1` using `pip install pyasn1 types-pyasn1`.
affects: all
gotchaTypeshed stub package versions follow a `X.Y.Z.YYYYMMDD` format. The `X.Y.Z` part indicates the `pyasn1` version the stubs target, while `YYYYMMDD` is the stub release date. Pinning only `X.Y.Z` (e.g., `types-pyasn1==0.6.0`) might still result in updates from newer daily stub releases if not fully pinned (e.g., `types-pyasn1==0.6.0.20260408`).fixFor strict dependency management, consider pinning the full version string including the date, or understand that the daily component might update even if the `X.Y.Z` part remains the same.
affects: all
breakingWhile typeshed aims for stability, changes within the stub files themselves can introduce stricter type checks or corrections that may cause existing, untyped, or loosely typed code using `pyasn1` to suddenly fail type checking, even if the runtime `pyasn1` version has not changed.fixRegularly review type checker output after updating `types-pyasn1`. If new type errors appear, adjust your code to satisfy the more accurate type hints or consider temporarily pinning to an older, compatible stub version while addressing the issues.
affects: all
Upgrade
Version history
0.6.0.20260724latest on PyPI · released Jul 24, 2026
Audit
Dependencies
pyasn1requiredThis package provides type hints for `pyasn1`. The `pyasn1` library itself must be installed separately for runtime execution.