My Simple Json Serializer and Naming Utilities
The main class is the serializer - HardSerializer
It's not particularly hard, just doesn't try to infer the class to deserialize (like my previous iterations), you need to specify the class directly. Also, it's fairly picky about the format of the class - you need to use typing EVERYWHERE or it doesn't work. It uses a lot of reflection to figure stuff out, and the typing is critical.
It can figure out enums, lists, hierarchies, etc. Pretty powerful. The json is standard, no tags or anything, and compatible with other languages and libraries like System.Text.Json in .NET
It essentially converts the object model into dicts and then json.dumps() them to serialize, the reverse for deserialize.
Usage
You need to specify the fields in the class definition as well as in the init - like so:
class TestClass(object):
id: int
name: str
guid: uuid.UUID
test_enum: TestEnum
def __init__(
self,
id: int = 0,
name: str = "",
guid: uuid.UUID = uuid.uuid4(),
test_enum: TestEnum = TestEnum.Undefined,
):
self.id = id
self.name = name
self.guid = guid
self.test_enum = test_enum
Note the typing hints everywhere
It can handle hierarchies as long as the type hints are there:
class ParentClass(object):
id: int
name: str
guid: uuid.UUID
test_enum: TestEnum
children: list[TestClass]
def __init__(
self,
id: int = 0,
name: str = "",
guid: uuid.UUID = uuid.uuid4(),
test_enum: TestEnum = TestEnum.Undefined,
children: list[TestClass] = [],
):
self.id = id
self.name = name
self.guid = guid
self.test_enum = test_enum
self.children = children
Unit tests are included to see usage, but the basics are:
tc = TestClass(12, "Bob", test_enum=TestEnum.Value1)
json = serializer.serialize(tc)
new_tc = serializer.de_serialize(json, TestClass)
It will try to deserialize into the TestClass
Naming
The naming is a bit weirder, and uses custom dictionaries to work - not sure how else to do it.
The project originated from trying to form decent property names from database fieldnames.
Usage
Create the Naming class instance from the 2 dictionaries, the standard word list and the bigwords list (specifies common word combinations that are hard to infer)
Create Name class instances by using naming.string_to_name()
The Name class instance has different methods on it like Pascal, Snake, etc.
Simple.
Building
python -m build
Deploying
python -m twine upload --repository pypi dist/*
Metadata
Release files for sb-serializer 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sb_serializer-0.0.3.tar.gz | 6.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sb_serializer-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.1 kB
Release files / sb_serializer-0.0.3.tar.gz
| Download URL | sb_serializer-0.0.3.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bd4e6e16cf24302527d35f26147ef1cc09c29c971a9219bccbf04bc901989d0d
|
|
BLAKE2b-256 checksum How to use checksums |
362427f699767c742753cee5b5935817e07fb84b1c333bdb7490ef445bbcf539
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Release files / sb_serializer-0.0.3-py3-none-any.whl
| Download URL | sb_serializer-0.0.3-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
958d689d49e553160478f091ba45f568a614708862fecce6871233a176e4409e
|
|
BLAKE2b-256 checksum How to use checksums |
09373132ece8fe6d3ac7a2a5547d041240b0506efd920cd9cf8936ecbedfef08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Security for sb-serializer 0.0.3
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.