vinta /
awesome-python
An opinionated list of Python frameworks, libraries, tools, and resources
90/100 healthLoading repository data…
P1sec / repository
A Python library to ease the development of encoders and decoders for various protocols and file formats; contains ASN.1 and CSN.1 compilers.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
The repository has moved to https://github.com/pycrate-org/pycrate and is now archived.
Pycrate is a french word for qualifying bad wine (when it's close to vinegar !). The present software library has nothing to do with wine (except it is developed in France), it is simply a Python library for manipulating various digital formats in an easy way, with a funny name. Most of the format supported are related in one way or another to cellular network's signalling. It is the glorious successor of libmich, which was started back in 2009, served well and retired in 2017.
It provides basically a runtime for encoding and decoding data structures, including CSN.1 and ASN.1. Additionally, it features a 3G and LTE mobile core network.
The whole library is licensed under LGPL v2.1 and is compatible with more recent version of the LGPL: all licensed files have an header making it self-explanatory. For more details, please report to the license.txt file.
Pycrate has a growing wiki. Use it as much as possible before opening an issue. Feel free also to propose some additional content.
The library is designed to work with Python 3 (3.5 and greater), from the official Python implementation CPython, and is systematically tested both on Linux, MacOS and Windows. It should also support alternative Python engines such as pypy, nuitka or Cython ; this is however not regularly tested. It should also support any other operating systems which has a decent Python 3 support.
Python2 support is entirely abandonned end of 2022, and hence release 0.5.5 is the last one with full support of Python 2.7.
Currently none. Only the Python builtins and few internal modules of Python (e.g. os, system, re, struct, datetime) are required for most of the features. The json internal module is required for supporting the JSON API. If you want to run pycrate in Python2 (which is bad !), you will however need to install the enum34 package.
The pycrate_ether/SCTP module can optionally use the external crc32c module from ICRAR.
The pycrate_mobile/TS24301_EMM and pycrate_mobile/TS24501_FGMM modules use CryptoMobile as optional dependency to encrypt and decrypt LTE and 5G NAS messages.
The pycrate_corenet part requires also pysctp and CryptoMobile to run.
The pycrate_diameter/parse_iana_diameter_xml.py file uses lxml to translate xml files from IANA to Python dictionnaries ; this is however not required for standard runtime.
The pycrate_osmo/SEDebugMux.py module relies on the crcmod to compute custom CRC in the frame format.
An installation script is available. As soon as you have cloned or downloaded the repository, you can use it to install the library within your Python package directory:
python setup.py install
Run it as superuser for a system-wide install, or as-is for a user home-directory level install. You can also run develop instead of install if you want a developer-friendly installation.
It is also possible to test the library before installing it (this will create two local directories ./test_asn/ and ./pycrate.egg-info/ that you can just delete afterwards):
python -m unittest test.test_pycrate
Or to build the library without installing it in the system:
python setup.py build
It is also possible to recompile all ASN.1 modules, this will take few minutes (but if I did not do any mistake, all ASN.1 modules provided in ./pycrate_asn1dir/ should have been compiled with the latest version of the compiler):
python -m pycrate_asn1c.asnproc
More generally, installation is not required, and simply having all pycrate_* subdirectories into the PYTHONPATH enables to use the entire library.
Alternatively, you can install the library with the pip command:
pip install pycrate
The install package is available on pypi. It contains the library from the last tagged release on github (which may be months old).
This library is free software, and you are free to use it (or not to use it). In case you encounter a problem with it, first read this README completely and then check the Wiki ; moreover many classes, methods and functions are documented with docstrings, and finally you can have a look at the source code (it won't bite you).
If after all those steps, you still have a question or you think you found a bug, please open an issue (see below). Specific support requires time and may not be always possible. In case you require such support, please consider also contributing in one way or another (see below, too).
In case you are using this library in any of your project and you find it useful, do not hesitate to send me an email. It is always a pleasure to know where code provided on the Internet can end up... (I am personally aware of some dark places where a pycrate's fork lies).
When filling an issue, please provide precise and contextual information about your case and the error you potentially encounter:
This is the bare minimum if you want to get help. And when you consider your issue has been addressed, please close it: "A good issue is a closed one !" as would have said my great grandmother.
If you are willing to extend the library, do not hesitate to contact me by email or preferably through the github service (ideally, open a pull request). For important changes, please elaborate about your need and provide some justification. Any patch or submission is always very welcome!
In case you do not want to deep dive in the code, you can still contribute in many ways:
Getting contributions is extremely important to encourage the continuous development of the library, and to confirm the choice made to open-source it.
Pycrate is actually more a software suite than a single library. It is composed of several subdirectories, each providing specific services.
The core of the library.
Some of the most useful features are provided by the pack_val() functions from the utils module and the Charpy class from the charpy module. They help to deal easily with packing and unpacking bytes and integers (signed / unsigned, little / big endian) in an aligned and unaligned way. All lengths of fields are provided in bits, hence facilitating the handling of unaligned structures.
The modules provided here implement Ethernet and IP-oriented protocols and formats.
The modules here implement various multimedia formats.
Most of the classes here implement a complete recipe to parse all of those format in a single shot, by using their from_char() method.
All the modules here serve the sole purpose of compiling ASN.1 specifications. The most important ones are:
This compiler support most of the ASN.1 language features, including parameterization and class objects and sets (especially useful when working with table constraints). It has however few restrictions, the biggest being the need for the left part of the ASN.1 assignment ::= being on a single line. Also, old-school ASN.1 macros are not supported ; hence, the compiler cannot parse SNMP MIBs.
This subdirectory contains several ASN.1 specifications that are supported and precompiled for pycrate. Very few specifications have been changed in order to work with pycrate :
This subdirectory contains the ASN.1 runtime, that is loaded and used by the ASN.1 specifications compiled with the compiler in pycrate_asn1c. It supports the PER encoding rules (aligned and not, canonical also), and the BER, CER, DER and JER encoding rules.
This subdirectory contains a CSN.1 to Python translater in the file trans.py, and a CSN.1 runtime in the file csnobj.py, in order to encode and decode CSN.1 structures translated to Python objects.
This subdirectory contains CSN.1 structures extracted from 3GPP specifications (in the .csn files), and translated into Python objects. The following specifications have been used: TS
Selected from shared topics, language and repository description—not editorial ratings.
vinta /
An opinionated list of Python frameworks, libraries, tools, and resources
90/100 healthTextualize /
Rich is a Python library for rich text and beautiful formatting in the terminal.
98/100 healthpsf /
A simple, yet elegant, HTTP library.
ccxt /
A unified trading API with more than 100 crypto exchanges and prediction markets in JavaScript / TypeScript / Python / C# / PHP / Go / Java
96/100 healthray-project /
Ray is an AI compute engine. Ray consists of a core distributed runtime and a set of AI Libraries for accelerating ML workloads.
91/100 healthgoogle /
A Python library for extracting structured information from unstructured text using LLMs with precise source grounding and interactive visualization.
97/100 health