Gelatin Extract
This is kind of like Marshmallow, but only does deserialization. What it lacks in reversibility, it makes up for in speed. Schemas are compiled in advance allowing deserialization to occur very quickly.
Motivation
I have another package called patent_client. I also do a lot with legal data, some of which is in XML, and some of which is in JSON. But there's a lot of it. And I mean a lot, so speed matters.
Quick Start
There are two main modules: gelatin_extract.json.schema and gelatin_extract.xml.schema. Those modules support defining class-style deserializers. Both start by subclassing a Schema class, and then defining attributes from the fields submodule.
JSON Deserializer Example
from gelatin_extract.json.schema import Schema
from gelatin_extract.json.schema import fields
class JsonExample(Schema):
name = fields.String()
birthday = fields.Date("birthdate")
deep_data = fields.Int("something.0.many.levels.deep")
obj = {
"name": "Johnny Appleseed",
"birthdate": "2000-01-01",
"something": [
{"many": {
"levels": {
"deep": 123
}
}}
]
}
JsonExample().deserialize(obj)
# Returns
{
"name": "Johnny Appleseed",
"birthday": datetime.date(2000, 1, 1),
"deep_data": 123
}
For JSON, the attributes are filled by pulling values off of the JSON object. If no path is provided, then the attribute name is used. Otherwise, a dotted string can be used to pluck an item from the JSON object.
XML Deserializer Example
import lxml.etree as ET
from sugar.xml.schema import Schema
from sugar.xml.schema import fields
class XmlExample(Schema):
name = fields.String("./name")
birthday = fields.Date("./birthdate")
deep_data = fields.Int("./something/many/levels/deep")
obj = ET.fromstring(b"""
<xmlObject>
<name>Johnny Appleseed</name>
<birthdate>2000-01-01</birthdate>
<something>
<many>
<levels>
<deep>123</deep>
</levels>
</many>
</something>
</xmlObject>
""".strip())
XmlExample().deserialize(obj)
# Returns
{
"name": "Johnny Appleseed",
"birthday": datetime.date(2000, 1, 1),
"deep_data": 123
}
For XML, the attributes are filled using XPath expressions. If no path is provided, then the entire object is passed to the field (no implicit paths). Any valid Xpath expression can be used.
Metadata
Release files for gelatin-extract 0.1.2
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 | Actions |
|---|---|---|---|---|
| gelatin_extract-0.1.2.tar.gz | 11.9 kB | Without provenance | Details for gelatin_extract-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gelatin_extract-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for gelatin_extract-0.1.2-py3-none-any.whl |
Total release size: 28.3 kB
Release files / gelatin_extract-0.1.2.tar.gz
| Download URL | gelatin_extract-0.1.2.tar.gz |
|---|---|
| Size | 11.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3dfae74db296b74397eddeb5c30b97de1543db8c54f637d09f55720e2cce7b0d
|
|
BLAKE2b-256 checksum How to use checksums |
01c29afdf7d246cc28716bdbda7a416c14ee54e3b692376d64fdfb82941b1304
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.6 CPython/3.9.12 Darwin/21.5.0
|
Release files / gelatin_extract-0.1.2-py3-none-any.whl
| Download URL | gelatin_extract-0.1.2-py3-none-any.whl |
|---|---|
| Size | 16.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7f51ea13339c395a872ea1cd9e38d6abea73afdb8c9fb3cee465d11b207f23f1
|
|
BLAKE2b-256 checksum How to use checksums |
9101b91f1730678b1b4d48775129ed72bc262758aa420c9af6bb5698f955d60d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.6 CPython/3.9.12 Darwin/21.5.0
|
Security for gelatin-extract 0.1.2
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.