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) { = id; = email;

const user = new User(1, '')
const {id, email} = user;  // destructure

unpackable allows you to do something similar in Python:

from dataclasses import dataclass
from unpackable import Unpackable

class User(Unpackable):
  id: int
  email: str

user = User(1, '')
id, email = user  # destructure

unpackable can also unpack objects that don't subclass Unpackable:

from unpackable import unpack

class User:
  id: int
  email: str

user = User(1, '')
id, email = unpack(user)  # destructure


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.



  • Python 3.8+


python3 -m pip install unpackable


Want to support this project and other open-source projects like it?

Buy Me A Coffee


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.4.tar.gz (6.7 kB view hashes)

Uploaded source

Built Distribution

unpackable-0.0.4-py2.py3-none-any.whl (7.9 kB view hashes)

Uploaded py2 py3

Supported by

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