Moschitta Serialization Documentation
moschitta-serialization is a Python package that provides serializers for converting data to and from various formats, including JSON, MessagePack, YAML, and Protobuf.
Table of Contents
Installation
To install moschitta-serialization, you'll need Python 3.7 or higher, as well as Poetry for dependency management and building the package.
-
Install Poetry: If you haven't already, install Poetry, a tool for dependency management and building Python packages. You can install it with the following command:
curl -sSL https://install.python-poetry.org | python -
-
Install Protobuf Compiler: The Protobuf compiler (
protoc) is required for compiling.protofiles into Python code. You can install it as follows:-
On Ubuntu/Debian:
sudo apt-get install protobuf-compiler
-
On macOS:
brew install protobuf
-
On Windows, download pre-compiled binaries from the Protocol Buffers GitHub repository. After downloading and unzipping the archive, add the
bin/directory to your PATH.
-
-
Install the Package: Navigate to the root directory of the
moschitta-serializationpackage and run the following command to install the package and its dependencies:poetry install
Usage
The moschitta-serialization package provides several serializers that you can use in your application. Here's an example of how to use the JSONSerializer:
from moschitta_serialization.json_serializer import JSONSerializer
serializer = JSONSerializer()
data = {"name": "John", "age": 30}
serialized_data = serializer.serialize(data)
print(serialized_data) # '{"name": "John", "age": 30}'
You can use the other serializers in a similar way.
Protobuf Serialization
To use the ProtobufSerializer, you'll need to define your Protobuf messages in .proto files, compile these files into Python code, and import the generated classes in your application.
-
Define Protobuf Messages: Create a
.protofile in theproto/directory and define your Protobuf messages in it. -
Compile
.protoFiles: Run thecompile_protos.pyscript to compile the.protofiles into Python code:python compile_protos.py -
Import Message Types: In your Python code, import the generated classes from the Python files:
from proto.person_pb2 import Person
You can then use these classes with the ProtobufSerializer.
Testing
The moschitta-serialization package includes a suite of tests that you can run with pytest. To run the tests, navigate to the root directory of the package and run the following command:
poetry run pytest
Contributing
Contributions to the moschitta-serialization package are welcome! Please submit a pull request or open an issue on the GitHub repository.
License
This project is licensed under the terms of the MIT License.
Release files for moschitta-serialization 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| moschitta_serialization-0.1.1.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| moschitta_serialization-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.7 kB
Release files / moschitta_serialization-0.1.1.tar.gz
| Download URL | moschitta_serialization-0.1.1.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07afe6b8a808e7a2e43aa2c9416e0c799f30a82ae318592ec447d6965323705c
|
|
BLAKE2b-256 checksum How to use checksums |
2bef4238f3f7f11069e676fa82dfc627d5a00cb6de96ccffcec53e93e0018ef0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.11.2 Linux/6.5.0-13parrot1-amd64
|
Release files / moschitta_serialization-0.1.1-py3-none-any.whl
| Download URL | moschitta_serialization-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
580acb7bbfa84264d40c26a879f02e213992e65a721c981f4cc944f257c89bcf
|
|
BLAKE2b-256 checksum How to use checksums |
138446dd0b8b67f03cec64969e7a48456db860f22f1b448e978ae4fb9f8a0f43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.11.2 Linux/6.5.0-13parrot1-amd64
|