Skip to main content

Pyser

PySer page on the Python Package Index https://github.com/jonnekaunisto/pyser/workflows/Python%20package/badge.svg https://codecov.io/gh/jonnekaunisto/pyser/branch/master/graph/badge.svg

PySer(full documentation) is a library for serializing and deserializing data in different data formats through intuitive mappings in defined inside a Python class.

Current formats supported are JSON and config files, with more coming later on.

Examples

Class mappings for serializing and deserializing in JSON

from pyser import SchemaJSON, SerField, DeserField
class FruitBasketSchema(SchemaJSON):
    def __init__(self):
        self.name           = DeserField()
        self.fruit          = DeserField()
        self.iD             = DeserField(name='ref', kind=int)
        self.intString      = DeserField(kind=int)
        self.optionalString = DeserField(kind=str, optional=True)
        self.items          = DeserField(repeated=True)

        self.name           = SerField()
        self.fruit          = SerField()
        self.iD             = SerField(name='ref', kind=int)
        self.intString      = SerField(kind=int)
        self.optionalString = SerField(optional=True)
        self.items          = SerField(repeated=True)
        self.register       = SerField(parent_keys=['checkout'], kind=int)
        self.amount         = SerField(parent_keys=['checkout'], kind=int)


fruit_basket_schema = FruitBasketSchema()


class FruitBasket():
    def __init__(self):
        self.name           = 'basket'
        self.fruit          = 'banana'
        self.iD             = '123'
        self.intString      = '12345'
        self.optionalString = None
        self.items          = ['paper', 'rock']
        self.register       = '1'
        self.amount         = '10'

Serializing to a JSON file

basket = FruitBasket()
fruit_basket_schema.to_json(basket, filename="basket.json")

File contents of basket.json after serializing:

{
    "name": "basket",
    "fruit": "banana",
    "ref": 123,
    "intString": 12345,
    "items": [
        "paper",
        "rock"
    ],
    "checkout": {
        "register": 1,
        "amount": 10
    }
}

Similarly deserialization from a json file:

basket = FruitBasket()
fruit_basket_schema.from_json(basket, raw_json=raw_json)

Installation

Installation by hand: you can download the source files from PyPi or Github:

python setup.py install

Installation with pip: make sure that you have pip installed, type this in a terminal:

pip install pyser

Documentation

Running build_docs has additional dependencies that require installation.

pip install pyser[docs]

The documentation can be generated and viewed via:

$ python setup.py build_docs

You can pass additional arguments to the documentation build, such as clean build:

$ python setup.py build_docs -E

More information is available from the Sphinx documentation.

Running Tests

Run the python command

python setup.py test

Contribute

  1. Fork the repository from Github

  2. Clone your fork

git clone https://github.com/yourname/pyser.git
  1. Add the main repository as a remote

git remote add upstream https://github.com/jonnekaunisto/pyser.git
  1. Create a pull request and follow the guidelines

Maintainers

Metadata

Release files for pyser 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyser 0.1.5
File Size Uploaded Provenance Actions
pyser-0.1.5.tar.gz 7.3 kB Without provenance Details for pyser-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyser 0.1.5
File Interpreter ABI Platform Actions
pyser-0.1.5-py3-none-any.whl Python 3 none any Details for pyser-0.1.5-py3-none-any.whl

Total release size: 14.5 kB

Release files / pyser-0.1.5.tar.gz

Download URL pyser-0.1.5.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
57e7adba7664d43b14e71519070b1e47925d71e027f50fc61441c051db7e5cc0
BLAKE2b-256 checksum
How to use checksums
7dd9974eef8b8c81f041a958479843bb2b5d4cf4c356777d0e9344d6b3e59bfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

Release files / pyser-0.1.5-py3-none-any.whl

Download URL pyser-0.1.5-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fce24292257e7da175bafa2a8cff05a58bfef4045a11aa70d18a9d139adb5ef0
BLAKE2b-256 checksum
How to use checksums
7856abcb86f855ac3b57823f2da2beaea21336af604aefe66193b34e08321301
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

Security for pyser 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page