python / cpython

The Python programming language
https://www.python.org
Other
63.41k stars 30.36k forks source link

Built-in function for generating UUIDv7 identifiers according to RFC9562 #121095

Closed sergeyprokhorenko closed 4 months ago

sergeyprokhorenko commented 4 months ago

Feature or enhancement

Proposal:

A long awaited new RFC 9562 "Universally Unique IDentifiers (UUIDs)" has been recently published. There is a pressing need to implement UUIDv7 with Fixed Bit-Length Dedicated Counter (Method 1) for Python for use as database keys.

The best choice is to take https://github.com/uuid-rs/uuid/issues/717 (it is perfect) as an example and add to it an optional formal parameter "timestamp offset" in milliseconds (positive or negative). Another good example: UUID v7

See also https://kodraus.github.io/rust/2024/06/24/uuid-v7-counters.html and https://www.reddit.com/r/rust/comments/1dn5ge4/uuid_now_properly_sorts_v7_ids/

Example of an existing implementation: quwac/newnewid-python

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

RFC 4122/9562: UUID version 7 and 8 implementation

hugovk commented 4 months ago

Thanks for the issue, this is a duplicate of https://github.com/python/cpython/issues/89083 and there's already a couple of alternative PRs to implement it.

Your input on the questions raised in the issue and discussion are welcome!