destructipy
es6 style dict/object destructure for python
install:
$ pip install destructipy
usage:
# must import this way...
from destructipy import _ as ds
# support dicts
abcd = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
# ds.i()/ds.item() - using operator.itemgetter
# dict safe, will probably raise error if not dict
d, c, \
b, a = ds.i(abcd)
print(a, b, c, d)
# func can be named however you wish...
from destructipy import _ as unpack
# supports objects
class ABCD:
a = 1
b = 2
abcd = ABCD()
abcd.c = 3
abcd.d = 4
# unpack.a()/unpack.attr() - using operator.attrgetter
# notice: dicts can also be passed but it will get their attributes, not items)
d, c, \
b, a = unpack.a(abcd)
print(a, b, c, d)
from destructipy import _ as ds
abcd_dict = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
class ABCD:
a = 5
b = 6
abcd_obj = ABCD()
abcd_obj.c = 7
abcd_obj.d = 8
# ds() - auto decide if it's dict or object
# good for one time or mixed dict-object/small lists
# got minor performance penalty, see benchmark below
d, c, b, a = ds(abcd_dict)
print(a, b, c, d)
d, c, b, a = ds(abcd_obj)
print(a, b, c, d)
caveats:
- Does not work on the Interactive Python Console (no source to analyze...)
- If you plan to compile your
.pyto.pycand delete the source, run$ python -m destructipyin your project root to create.destructipycache file before doing so - It is recommended to place a
import destructipyon your project init for destructipy to keep the initial cwd (current working directory), just incase you switch the cwd later on usingos.chdiror such... - using sys._getframe which is only implemented at CPython. tested on 2.7 and 3.8
benchmark:
$ python benchmark.py
9 iterations:
regular : 0:00:00.000009
ds : 0:00:00.000100
ds.i/ds.a : 0:00:00.000024
99 iterations:
regular : 0:00:00.000020
ds : 0:00:00.000066
ds.i/ds.a : 0:00:00.000061
999 iterations:
regular : 0:00:00.000164
ds : 0:00:00.000568
ds.i/ds.a : 0:00:00.000521
9999 iterations:
regular : 0:00:00.001409
ds : 0:00:00.005194
ds.i/ds.a : 0:00:00.004448
99999 iterations:
regular : 0:00:00.011635
ds : 0:00:00.045619
ds.i/ds.a : 0:00:00.040462
999999 iterations:
regular : 0:00:00.104921
ds : 0:00:00.396913
ds.i/ds.a : 0:00:00.377507
9999999 iterations:
regular : 0:00:01.034074
ds : 0:00:03.985506
ds.i/ds.a : 0:00:03.883992
99999999 iterations:
regular : 0:00:10.758053
ds : 0:00:46.962093
ds.i/ds.a : 0:00:45.535044
999999999 iterations:
regular : 0:02:00.999255
ds : 0:08:04.748202
ds.i/ds.a : 0:07:42.837535
Metadata
Release files for destructipy 0.0.5
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 |
|---|---|---|---|---|
| destructipy-0.0.5.tar.gz | 3.5 kB | Without provenance | Details for destructipy-0.0.5.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| destructipy-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for destructipy-0.0.5-py3-none-any.whl |
| destructipy-0.0.5-py2-none-any.whl | Python 2 | none | any | Details for destructipy-0.0.5-py2-none-any.whl |
Total release size: 12.4 kB
Release files / destructipy-0.0.5.tar.gz
| Download URL | destructipy-0.0.5.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6d4c80988c935ab46eeeede34d904cfa2ac759d3fbb5ad2435cfa09f3a1a63f
|
|
BLAKE2b-256 checksum How to use checksums |
d9ba22c45b43750fc959536fd863e51a9ac1194244bc25b77317e06ab0c01beb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.6.0 requests-toolbelt/0.8.0 tqdm/4.48.2 CPython/3.8.5
|
Release files / destructipy-0.0.5-py3-none-any.whl
| Download URL | destructipy-0.0.5-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f2a88fada357e3099324a25178ba54aa2bd3b9bb116e9c33d3b27524dc836b73
|
|
BLAKE2b-256 checksum How to use checksums |
9dd5520e8657e8a2bf6ae0e36b051d48c0cacf26290eccfed9b7eab58128dceb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.6.0 requests-toolbelt/0.8.0 tqdm/4.48.2 CPython/3.8.5
|
Release files / destructipy-0.0.5-py2-none-any.whl
| Download URL | destructipy-0.0.5-py2-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
4e416f5b54e93f00fa8fdd337223dc553e355ef5281ae85874cec68503e52721
|
|
BLAKE2b-256 checksum How to use checksums |
0739d2514114721e04eb1c0ef3c31c96627afe4c32d25840152485f3f6cf48d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.6.0 requests-toolbelt/0.8.0 tqdm/4.48.2 CPython/3.8.5
|
Security for destructipy 0.0.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.