Skip to main content
rekey
======
Transform collections into dicts by deriving keys from each item.


### Install
```pip install rekey```


### Usage
```
from rekey import rekey

# key a list of records by id
people = [
{ 'id' : 1, 'name' : 'alice', 'age' : 30 },
{ 'id' : 2, 'name' : 'bob', 'age' : 24 },
{ 'id' : 3, 'name' : 'charlie', 'age' : 88 },
]
rekey(people, 'id')
=> {
1 => { 'id' : 1, 'name' : 'alice', 'age' : 30},
2 => { 'id' : 2, 'name' : 'bob', 'age' : 24},
3 => { 'id' : 3, 'name' : 'charlie', 'age' : 88},
}

# create an id => value map
rekey(people, 'id', 'name')
=> {
1 => 'alice',
2 => 'bob',
3 => 'charlie',
}


# use Rekeyables for built-in functionality

from rekey.rekeyable import RekeyableSet

Point = namedtuple('Point', ['name', 'x', 'y']) # hashable
points = RekeyableSet([
Point(name='home', x=1, y=2),
Point(name='work', x=3, y=6),
])
points.rekey('name')
=> {
'home' : Point(name='home', x=1, y=2),
'work' : Point(name='work', x=3, y=6),
}


# use the Rekeyable mixin to build your own

from rekey.rekeyable import Rekeyable
class MyDict(dict, Rekeyable): pass

MyDict({
'home' : {'distance' : 1, 'weather' : 'sunny' },
'work' : {'distance' : 5, 'weather' : 'foggy' },
}).rekey('weather', 'distance')
> {
'sunny' : 1,
'foggy' : 5,
}
```

Metadata

Release files for rekey 1.2.3

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

Source distribution (sdist)

Source distribution for rekey 1.2.3
File Size Uploaded Provenance Actions
rekey-1.2.3.tar.gz 4.6 kB Without provenance Details for rekey-1.2.3.tar.gz

Release files / rekey-1.2.3.tar.gz

Download URL rekey-1.2.3.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9687d501c7631ff337ec0bce0b1071fa57c38cc4f4b615fa0cf9611013406375
BLAKE2b-256 checksum
How to use checksums
b565b839b36308d62d10cf078463dfe3974103982308d1bf7a763b330aab33d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.7

Security for rekey 1.2.3

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.

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