Registry / type-stubs / types-pyasn1

types-pyasn1

JSON →
library0.6.0.20260724pypypi✓ verified 25d ago

This package provides typing stubs for the `pyasn1` library, enabling static type checkers like MyPy and PyRight to validate code that uses `pyasn1`. It is part of the typeshed project, a collection of high-quality type annotations, and aims to provide accurate annotations for `pyasn1==0.6.*`. Typeshed releases stub packages automatically, often up to once a day, reflecting changes and improvements to the types.

pip install types-pyasn1
INSTALL
IMPORT
SIG · TYPES-PYASN1
T
types-pyasn1
type-stubspythonv0.6.0.20260724
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.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.
fix
Ensure 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.
fix
Install `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`).
fix
For 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.
fix
Regularly 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.
Agent activity
34 hits · last 30 days
node
32
OpenAI (training)
1
Resources