{"id":13725351,"url":"https://github.com/etingof/pyasn1","last_synced_at":"2025-10-21T06:21:35.085Z","repository":{"id":45322836,"uuid":"52479161","full_name":"etingof/pyasn1","owner":"etingof","description":"Generic ASN.1 library for Python","archived":false,"fork":false,"pushed_at":"2023-11-21T11:16:12.000Z","size":1750,"stargazers_count":241,"open_issues_count":60,"forks_count":118,"subscribers_count":33,"default_branch":"master","last_synced_at":"2024-08-04T01:27:40.576Z","etag":null,"topics":["asn","network-protocols","protocols","pyasn1","python"],"latest_commit_sha":null,"homepage":"http://snmplabs.com/pyasn1","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/etingof.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.rst","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.rst","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"custom":"http://snmplabs.com/sponsorship.html"}},"created_at":"2016-02-24T22:30:54.000Z","updated_at":"2024-07-17T18:37:23.000Z","dependencies_parsed_at":"2024-01-08T02:02:26.718Z","dependency_job_id":null,"html_url":"https://github.com/etingof/pyasn1","commit_stats":{"total_commits":895,"total_committers":16,"mean_commits":55.9375,"dds":0.5162011173184358,"last_synced_commit":"db8f1a7930c6b5826357646746337dafc983f953"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etingof%2Fpyasn1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etingof%2Fpyasn1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etingof%2Fpyasn1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etingof%2Fpyasn1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/etingof","download_url":"https://codeload.github.com/etingof/pyasn1/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224645341,"owners_count":17346128,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asn","network-protocols","protocols","pyasn1","python"],"created_at":"2024-08-03T01:02:20.277Z","updated_at":"2025-10-21T06:21:30.055Z","avatar_url":"https://github.com/etingof.png","language":"Python","funding_links":["http://snmplabs.com/sponsorship.html"],"categories":["Python","Codec Implementations"],"sub_categories":["Codec Standards"],"readme":"\nASN.1 library for Python\n------------------------\n[![PyPI](https://img.shields.io/pypi/v/pyasn1.svg?maxAge=2592000)](https://pypi.org/project/pyasn1)\n[![Python Versions](https://img.shields.io/pypi/pyversions/pyasn1.svg)](https://pypi.org/project/pyasn1/)\n[![Build status](https://travis-ci.org/etingof/pyasn1.svg?branch=master)](https://secure.travis-ci.org/etingof/pyasn1)\n[![Coverage Status](https://img.shields.io/codecov/c/github/etingof/pyasn1.svg)](https://codecov.io/github/etingof/pyasn1)\n[![GitHub license](https://img.shields.io/badge/license-BSD-blue.svg)](https://raw.githubusercontent.com/etingof/pyasn1/master/LICENSE.txt)\n\nThis is a free and open source implementation of ASN.1 types and codecs\nas a Python package. It has been first written to support particular\nprotocol (SNMP) but then generalized to be suitable for a wide range\nof protocols based on\n[ASN.1 specification](https://www.itu.int/rec/dologin_pub.asp?lang=e\u0026id=T-REC-X.208-198811-W!!PDF-E\u0026type=items).\n\nFeatures\n--------\n\n* Generic implementation of ASN.1 types (X.208)\n* Standards compliant BER/CER/DER codecs\n* Can operate on streams of serialized data\n* Dumps/loads ASN.1 structures from Python types\n* 100% Python, works with Python 2.7 and 3.5+\n* MT-safe\n* Contributed ASN.1 compiler [Asn1ate](https://github.com/kimgr/asn1ate)\n\nWhy using pyasn1\n----------------\n\nASN.1 solves the data serialisation problem. This solution was\ndesigned long ago by the wise Ancients. Back then, they did not\nhave the luxury of wasting bits. That is why ASN.1 is designed\nto serialise data structures of unbounded complexity into\nsomething compact and efficient when it comes to processing\nthe data.\n\nThat probably explains why many network protocols and file formats\nstill rely on the 30+ years old technology. Including a number of\nhigh-profile Internet protocols and file formats.\n\nQuite a number of books cover the topic of ASN.1. \n[Communication between heterogeneous systems](http://www.oss.com/asn1/dubuisson.html)\nby Olivier Dubuisson is one of those high quality books freely \navailable on the Internet.\n\nThe pyasn1 package is designed to help Python programmers tackling\nnetwork protocols and file formats at the comfort of their Python\nprompt. The tool struggles to capture all aspects of a rather\ncomplicated ASN.1 system and to represent it on the Python terms.\n\nHow to use pyasn1\n-----------------\n\nWith pyasn1 you can build Python objects from ASN.1 data structures.\nFor example, the following ASN.1 data structure:\n\n```bash\nRecord ::= SEQUENCE {\n  id        INTEGER,\n  room  [0] INTEGER OPTIONAL,\n  house [1] INTEGER DEFAULT 0\n}\n```\n\nCould be expressed in pyasn1 like this:\n\n```python\nclass Record(Sequence):\n    componentType = NamedTypes(\n        NamedType('id', Integer()),\n        OptionalNamedType(\n            'room', Integer().subtype(\n                implicitTag=Tag(tagClassContext, tagFormatSimple, 0)\n            )\n        ),\n        DefaultedNamedType(\n            'house', Integer(0).subtype(\n                implicitTag=Tag(tagClassContext, tagFormatSimple, 1)\n            )\n        )\n    )\n```\n\nIt is in the spirit of ASN.1 to take abstract data description \nand turn it into a programming language specific form.\nOnce you have your ASN.1 data structure expressed in Python, you\ncan use it along the lines of similar Python type (e.g. ASN.1\n`SET` is similar to Python `dict`, `SET OF` to `list`):\n\n```python\n\u003e\u003e\u003e record = Record()\n\u003e\u003e\u003e record['id'] = 123\n\u003e\u003e\u003e record['room'] = 321\n\u003e\u003e\u003e str(record)\nRecord:\n id=123\n room=321\n\u003e\u003e\u003e\n```\n\nPart of the power of ASN.1 comes from its serialisation features. You\ncan serialise your data structure and send it over the network.\n\n```python\n\u003e\u003e\u003e from pyasn1.codec.der.encoder import encode\n\u003e\u003e\u003e substrate = encode(record)\n\u003e\u003e\u003e hexdump(substrate)\n00000: 30 07 02 01 7B 80 02 01 41\n```\n\nConversely, you can turn serialised ASN.1 content, as received from\nnetwork or read from a file, into a Python object which you can\nintrospect, modify, encode and send back.\n\n```python\n\u003e\u003e\u003e from pyasn1.codec.der.decoder import decode\n\u003e\u003e\u003e received_record, rest_of_substrate = decode(substrate, asn1Spec=Record())\n\u003e\u003e\u003e\n\u003e\u003e\u003e for field in received_record:\n\u003e\u003e\u003e    print('{} is {}'.format(field, received_record[field]))\nid is 123\nroom is 321\nhouse is 0\n\u003e\u003e\u003e\n\u003e\u003e\u003e record == received_record\nTrue\n\u003e\u003e\u003e received_record.update(room=123)\n\u003e\u003e\u003e substrate = encode(received_record)\n\u003e\u003e\u003e hexdump(substrate)\n00000: 30 06 02 01 7B 80 01 7B\n```\n\nThe pyasn1 classes struggle to emulate their Python prototypes (e.g. int,\nlist, dict etc.). But ASN.1 types exhibit more complicated behaviour.\nTo make life easier for a Pythonista, they can turn their pyasn1\nclasses into Python built-ins:\n\n```python\n\u003e\u003e\u003e from pyasn1.codec.native.encoder import encode\n\u003e\u003e\u003e encode(record)\n{'id': 123, 'room': 321, 'house': 0}\n```\n\nOr vice-versa -- you can initialize an ASN.1 structure from a tree of\nPython objects:\n\n```python\n\u003e\u003e\u003e from pyasn1.codec.native.decoder import decode\n\u003e\u003e\u003e record = decode({'id': 123, 'room': 321, 'house': 0}, asn1Spec=Record())\n\u003e\u003e\u003e str(record)\nRecord:\n id=123\n room=321\n\u003e\u003e\u003e\n```\n\nWith ASN.1 design, serialisation codecs are decoupled from data objects,\nso you could turn every single ASN.1 object into many different \nserialised forms. As of this moment, pyasn1 supports BER, DER, CER and\nPython built-ins codecs. The extremely compact PER encoding is expected\nto be introduced in the upcoming pyasn1 release.\n\nMore information on pyasn1 APIs can be found in the\n[documentation](http://snmplabs.com/pyasn1/),\ncompiled ASN.1 modules for different protocols and file formats\ncould be found in the pyasn1-modules \n[repo](https://github.com/etingof/pyasn1-modules).\n\nHow to get pyasn1\n-----------------\n\nThe pyasn1 package is distributed under terms and conditions of 2-clause\nBSD [license](http://snmplabs.com/pyasn1/license.html). Source code is freely\navailable as a GitHub [repo](https://github.com/etingof/pyasn1).\n\nYou could `pip install pyasn1` or download it from [PyPI](https://pypi.org/project/pyasn1).\n\nIf something does not work as expected, \n[open an issue](https://github.com/etingof/pyasn1/issues) at GitHub or\npost your question [on Stack Overflow](https://stackoverflow.com/questions/ask)\nor try browsing pyasn1 \n[mailing list archives](https://sourceforge.net/p/pyasn1/mailman/pyasn1-users/).\n\nCopyright (c) 2005-2020, [Ilya Etingof](mailto:etingof@gmail.com).\nAll rights reserved.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fetingof%2Fpyasn1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fetingof%2Fpyasn1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fetingof%2Fpyasn1/lists"}