This is the Python runtime library for the ASN.1 SCC compiler, providing ASN.1-specific types and encoding/decoding operations.
The asn1python library provides:
- Sized Integer Types:
UInt8,UInt16,UInt32,UInt64,Int8,Int16,Int32,Int64with overflow checking - ASN.1 Semantic Types:
Asn1Real,Asn1Boolean,NullType,Asn1ObjectIdentifier - Time Types:
Asn1Date,Asn1LocalTime,Asn1UtcTime,Asn1DateLocalTime - Encoding/Decoding: Support for UPER, ACN, XER, and BER encoding rules
- Bitstream Operations: Precise bit-level manipulation
- Cross-Language Compatibility: Identical binary output with C, Ada, and Scala implementations
pip install -e .This library is primarily used by code generated from the ASN.1 SCC compiler. For manual usage:
from asn1python import UInt8, UInt16, BitStream, UPERCodec
# Create sized integers
value = UInt8(255) # 8-bit unsigned integer
# Bitstream operations
stream = BitStream()
stream.write_bits(value.value, 8)
# UPER encoding
codec = UPERCodec()
encoded = codec.encode_integer(value, min_val=0, max_val=255)This library is automatically used by Python code generated from ASN.1 specifications:
# Generated Python code uses runtime types
from asn1python import UInt8, UInt16, Asn1Real
@dataclass
class MySequence:
field1: UInt8
field2: UInt16
field3: Asn1RealRun tests:
pytest tests/Type checking:
mypy src/asn1python/Code formatting:
black src/ tests/The library follows the same architectural patterns as the C, Ada, and Scala runtime libraries:
- types.py: Core ASN.1 types and operations
- bitstream.py: Bit-level operations
- codec.py*: Encoding/decoding for different ASN.1 encoding rules
- helper.py: Utility functions
- verification.py: Constraint validation
This library is part of the ASN.1 SCC project and follows the same licensing terms.