dictremapper
dictremapper is remapping dict library
ordered (important)
support inheritance (of mapper)
support nested structure
(excludes option of each layer)
simple example
import requests
import json
from dictremapper import Remapper, Path
class SummaryRemapper(Remapper):
fullname = Path("full_name")
url = Path("html_url")
description = Path("description")
url = "https://api.github.com/repos/podhmo/dictremapper"
data = requests.get(url).json()
data = SummaryRemapper()(data)
print(json.dumps(data, indent=2))
output
{
"fullname": "podhmo/dictremapper",
"url": "https://github.com/podhmo/dictremapper",
"description": "remapping dict"
}
support inheritance (of mapper)
from dictremapper import Remapper, Path
class URLRemapper(Remapper):
url = Path("html_url")
class DescriptionRemapper(Remapper):
fullname = Path("full_name")
description = Path("description")
class SummaryRemapper(URLRemapper, DescriptionRemapper):
star = Path("stargazers_count")
url = "https://api.github.com/repos/podhmo/dictremapper"
data = requests.get(url).json()
remapped = SummaryRemapper()(data)
print(json.dumps(remapped, indent=2))
output
{
"url": "https://github.com/podhmo/dictremapper",
"fullname": "podhmo/dictremapper",
"description": "remapping dict",
"star": 0
}
If you want to change order. ChangeOrder is helpful, maybe.
from dictremapper import ChangeOrder
class SummaryRemapper2(URLRemapper, DescriptionRemapper):
url = ChangeOrder(URLRemapper.url)
description = ChangeOrder(DescriptionRemapper.description)
star = Path("stargazers_count")
remapped = SummaryRemapper2()(data)
print(json.dumps(remapped, indent=2))
output
{
"fullname": "podhmo/dictremapper",
"url": "https://github.com/podhmo/dictremapper",
"description": "remapping dict",
"star": 0
}
support nested structure
class MyMapper3(Remapper):
body = Path("body", callback=MyMapper())
children = Path("children", callback=MyMapper2(many=True))
excludes option of each layer
class MyMapper3(Remapper):
body = Path("body", callback=MyMapper())
children = Path("children", callback=MyMapper2(many=True, excludes=["object.name", "object.age", "id"]))
MyMapper3(excludes=["children.object.description", "body"])(d)
Metadata
Release files for dictremapper 0.0.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 |
|---|---|---|---|---|
| dictremapper-0.0.2.tar.gz | 3.7 kB | Without provenance | Details for dictremapper-0.0.2.tar.gz |
Release files / dictremapper-0.0.2.tar.gz
| Download URL | dictremapper-0.0.2.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
abed7ae70a003244d45fd67b477aa83424086d71d6730b44ad975c32c9bf6124
|
|
BLAKE2b-256 checksum How to use checksums |
05f0b9710c6c852b7b75f270598c92d3178dc7cc1c756ec07ccefce9276453c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for dictremapper 0.0.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.