Converters
Install
Install using pip:
pip install python-converters
Overview
At its most basic, Converters provides a small in-python DSL / declarative mechanism to define transformations operations (”conversions") that allow you to rename, alter, add, clean etc. fields of objects / maps conveniently, making it easy to work with nested structures and a host of other common cases.
Here is a quick example of using a subclass of Converter to convert from one
instance to another:
from converters import Converter
class MyConverter(Converter):
from_class = dict
to_class = dict
conversions = [
'a', # to['a'] = from['a']
('b', 'a'), # to['b'] = from['a']
('c', NOS, 'a default'), # to['c'] = 'a default'
('d', 'a', lambda x: x * 2), # to['d'] = from['a'] * 2
('e', NOS, dict), # to['e'] = dict()
]
MyConverter({'a': 1}).convert()
# yields {'a': 1, 'b': 1, 'c': 'a default', 'd': 2, 'e': {}}
But that is just the beginning. Its real power comes as you start to nest converters and subclass the core converter class to support different data formats. The power of it is that you can get going with very simple examples, but as your needs grow you’ll find that converters rises to meet them, and are highly extendable for the cases where they don’t.
And to get you started there are already extensions for converting to and from:
- django models
- XML documents
- pandas dataframes
- fixed width string formats (!)
Why is this useful?
Doing conversions of data (e.g. ingest, exgest) normally seems like a simple job, but naive approaches end up writing a lot of (often one-off) boilerplate and repetitive code that is hard to read and update, inconsistent and error prone, with code often spread throughout several ad hoc functions. Converters provides a single place to put conversions, uses class inheritance to share domain-specific operations, and through that and its maximal approach to features minimizes client boilerplate.
Metadata
Release files for python-converters 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 | Provenance | |
|---|---|---|---|---|
| python_converters-0.1.1.tar.gz | 25.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_converters-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 52.8 kB
Release files / python_converters-0.1.1.tar.gz
| Download URL | python_converters-0.1.1.tar.gz |
|---|---|
| Size | 25.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8fc2472d28c47f4567216ef320fb752500dcfebc2cba083b3094269c7f378df6
|
|
BLAKE2b-256 checksum How to use checksums |
3461287620d90ceaaa15db9c706be0260a9a04a94fb6ce7464da59bbf1faebfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.10.6 Darwin/22.6.0
|
Release files / python_converters-0.1.1-py3-none-any.whl
| Download URL | python_converters-0.1.1-py3-none-any.whl |
|---|---|
| Size | 27.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc080dd4fc27ed126b56c64ca1673077014d68107e315061cb30129e488a484f
|
|
BLAKE2b-256 checksum How to use checksums |
4eba51d9625f07524c51f1e1e4477e37ad4f76d0d69ca73e334794846c93a4d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.10.6 Darwin/22.6.0
|
Security for python-converters 0.1.1
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.