Skip to main content

📦 Destructure Python objects

Project description

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 dataclasses import dataclass
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?

Buy Me A Coffee

License

See LICENSE. If you'd like to use this project with a different license, please get in touch.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unpackable-0.0.2.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unpackable-0.0.2-py2.py3-none-any.whl (7.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file unpackable-0.0.2.tar.gz.

File metadata

  • Download URL: unpackable-0.0.2.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.10.0b3+

File hashes

Hashes for unpackable-0.0.2.tar.gz
Algorithm Hash digest
SHA256 601ee86951ffdc864be712b4bf53b46df62eeb761a9fa7b362787ba2f967db80
MD5 575dfdb8c84f35677bbbcbbec56d7a49
BLAKE2b-256 3d9b60c7e4338c5e30796ab01485664612d4879e0ffdce96dded14ffc1b5905e

See more details on using hashes here.

File details

Details for the file unpackable-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: unpackable-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.10.0b3+

File hashes

Hashes for unpackable-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9cf7c1bfca8a844034c1b0786c352a09f181df27bc4beebb19826a6a0974a0a3
MD5 e0ea1718372f00d87508e8f83afdac7c
BLAKE2b-256 9eaa42784125185c6c49eee32b461360589e78e7f8ea10e8acdd4cd96d8de974

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page