Unpackable: Object destructuring for Python
unpackable is a module that lets you use Python's destructuring assignment to unpack an object's attributes.
Use case
Consider JavaScript's destructuring assignment feature that allows you to do the following:
class User {
constructor(id, email) {
this.id = id;
this.email = email;
}
}
const user = new User(1, 'example@example.com')
const {id, email} = user; // destructure
unpackable allows you to do something similar in Python:
from dataclasses import dataclass
from unpackable import Unpackable
@dataclass
class User(Unpackable):
id: int
email: str
user = User(1, 'example@example.com')
id, email = user # destructure
unpackable can also unpack objects that don't subclass Unpackable:
from unpackable import unpack
@dataclass
class User:
id: int
email: str
user = User(1, 'example@example.com')
id, email = unpack(user) # destructure
Status
unpackable currently works with iterable objects, dataclasses and simple objects.
This is alpha software and is not ready for use beyond limited use cases like in my app_paths project.
Installation
Requirements
- Python 3.8+
PyPI
python3 -m pip install unpackable
Support
Want to support this project and other open-source projects like it?
License
See LICENSE. If you'd like to use this project with a different license, please get in touch.
Metadata
Release files for unpackable 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| unpackable-0.0.4.tar.gz | 6.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| unpackable-0.0.4-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 14.5 kB
Release files / unpackable-0.0.4.tar.gz
| Download URL | unpackable-0.0.4.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
55185896c71f607f43e8cbe22913e46083baf2371ecd1c8a06f0bf93ab76f38d
|
|
BLAKE2b-256 checksum How to use checksums |
b01da7b462d4ef897e1119acc86e6426b39b7c59eea79e3d08a0cf0b43fbbda2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
|
Release files / unpackable-0.0.4-py2.py3-none-any.whl
| Download URL | unpackable-0.0.4-py2.py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
addb1bc7d01d8d1b64a0fc41a5f05bb49a62fe8fe730630d2cd04e4231cfc661
|
|
BLAKE2b-256 checksum How to use checksums |
18a7549e3e8d13181c137a9174a128c33dcbfc77efd5f457b82054b96f768143
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
|