Skip to main content

PyID

Python 3.7

Turn any python object into an exactly equivalent object with an id attribute.

Example

import random
import pyid


mylist = [random.sample(range(10), k=3) for i in range(20)]


# Uses python uuid module to assign ID by default
mylist = [pyid.idfy(item) for item in mylist]
for item in mylist:
    print(item, item.id)


# Assign a custom ID
mylist = [pyid.idfy(item, 'myid') for item in mylist]
for item in mylist:
    print(item, item.id)

Installation

pip install pyid

Motivation

When referencing related objects, we use unique IDs. In python, we might handle this pattern with a dictionary mapping IDs to objects, or use an item's position in a list as its ID. Either case requires we create variables separate from the object to represent those IDs, and that each time we iterate we explicitly include the ID by iterating with the ID dict or the enumerate function for lists. I built this to test the idea that having an ID attribute is easier and cleaner.

How it works

It takes the type of the passed object, creates a subclass of that type, with an ID attribute, and copies the data from the passed object into an instance that new subclass. If a custom ID is not passed, the python uuid module is used to assign one.

Metadata

Release files for pyid 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyid 0.0.2
File Size Uploaded
pyid-0.0.2.tar.gz 1.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyid 0.0.2
File Interpreter ABI Platform
pyid-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 3.5 kB

Release files / pyid-0.0.2.tar.gz

Download URL pyid-0.0.2.tar.gz
Size 1.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9bd336a77ac196e1d70495945a3f47a3ede40d452488c8fdf84d7e822ddf3fc7
BLAKE2b-256 checksum
How to use checksums
a725f390de70148a3bccf59a73066c86647ea8217fadea448c7cae56d45e260a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.6.6

Release files / pyid-0.0.2-py3-none-any.whl

Download URL pyid-0.0.2-py3-none-any.whl
Size 1.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aabc42689301603bd8cb97f8364ef39fc8da0957c01b60c7e5286009b24c7d70
BLAKE2b-256 checksum
How to use checksums
09655cf469d71cca17a0c54275c98cda9e8c7106a675a727d439bf045581d8aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.6.6

Release history Release notifications | RSS feed

0.0.3

2 release files

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page