{"id":21238638,"url":"https://github.com/zaczero/zid","last_synced_at":"2026-01-26T00:39:16.953Z","repository":{"id":246823839,"uuid":"823814207","full_name":"Zaczero/zid","owner":"Zaczero","description":"zid is a unique identifier with nice properties","archived":false,"fork":false,"pushed_at":"2024-10-26T01:59:14.000Z","size":86,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-09T23:51:55.242Z","etag":null,"topics":["identifier","primary-key","unique-identifier","uuid"],"latest_commit_sha":null,"homepage":"https://pypi.org/p/zid","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Zaczero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-03T19:18:37.000Z","updated_at":"2024-10-29T20:46:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"22bb9250-b8e1-46f6-992c-fa2de2f470fc","html_url":"https://github.com/Zaczero/zid","commit_stats":null,"previous_names":["zaczero/zid"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/Zaczero/zid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaczero%2Fzid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaczero%2Fzid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaczero%2Fzid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaczero%2Fzid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zaczero","download_url":"https://codeload.github.com/Zaczero/zid/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaczero%2Fzid/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28762935,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T00:37:26.264Z","status":"ssl_error","status_checked_at":"2026-01-26T00:37:25.959Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["identifier","primary-key","unique-identifier","uuid"],"created_at":"2024-11-21T00:36:56.300Z","updated_at":"2026-01-26T00:39:16.938Z","avatar_url":"https://github.com/Zaczero.png","language":"Rust","funding_links":["https://liberapay.com/Zaczero/","https://github.com/sponsors/Zaczero"],"categories":[],"sub_categories":[],"readme":"# ZID\n\n[![PyPI - Python Version](https://shields.monicz.dev/pypi/pyversions/zid)](https://pypi.org/project/zid)\n[![Liberapay Patrons](https://shields.monicz.dev/liberapay/patrons/Zaczero?logo=liberapay\u0026label=Patrons)](https://liberapay.com/Zaczero/)\n[![GitHub Sponsors](https://shields.monicz.dev/github/sponsors/Zaczero?logo=github\u0026label=Sponsors\u0026color=%23db61a2)](https://github.com/sponsors/Zaczero)\n\n**zid** is a unique identifier with nice properties:\n\n- It behaves like a 64-bit signed integer, so it can be safely used with external software, e.g., in a database. ZIDs will never overflow into negative values.\n\n- ZIDs are numerically sortable since the timestamp is stored in the most significant bits. Additional randomness is stored only in the least significant bits.\n\n- The specification is very simple, reducing the potential for bugs and making ZIDs highly efficient to generate and parse. Scroll down for the installation-free copy-and-paste code - it's that short!\n\n- CSPRNG-initialized sequence numbers enhance the privacy of the generated identifiers while remaining collision-resistant. You can generate up to 65,536 ZIDs within the same millisecond timestamp on a single machine.\n\n## Installation\n\nThe recommended installation method is through the PyPI package manager. The project is implemented in Rust, offering excellent performance characteristics. Several pre-built binary wheels are available for Linux, macOS, and Windows, with support for both x64 and ARM architectures.\n\n```sh\npip install zid\n```\n\n## Installation (copy \u0026 paste)\n\nAlternatively, you can copy and paste the following code for an installation-free ZID generator. This code excludes performance optimizations and utility methods for the sake of simplicity and portability:\n\n```py\nfrom os import urandom\nfrom time import time_ns\n\n_last_time: int = -1\n_last_sequence: int = -1\n\ndef zid() -\u003e int:\n    global _last_time, _last_sequence\n\n    # UNIX timestamp in milliseconds\n    time: int = time_ns() // 1_000_000\n    if time \u003e 0x7FFF_FFFF_FFFF:\n        raise OverflowError('Time value is too large')\n\n    # CSPRNG-initialized sequence numbers\n    sequence: int\n    if _last_time == time:\n        _last_sequence = sequence = (_last_sequence + 1) \u0026 0xFFFF\n    else:\n        _last_sequence = sequence = int.from_bytes(urandom(2))\n        _last_time = time\n\n    return (time \u003c\u003c 16) | sequence\n```\n\n## Basic usage\n\n```py\nfrom zid import zid\nzid()  # -\u003e 112723768038396241\nzid()  # -\u003e 112723768130153517\nzid()  # -\u003e 112723768205368402\n\nfrom zid import zids\nzids(3)\n# -\u003e [113103096068704205, 113103096068704206, 113103096068704207]\n\nfrom zid import parse_zid_timestamp\nparse_zid_timestamp(112723768038396241)\n# -\u003e 1720028198828 (UNIX timestamp in milliseconds)\n```\n\n## Format specification\n\nZID is 64 bits long in binary. Only 63 bits are used to fit in a signed integer. The first 47 bits are a UNIX timestamp in milliseconds. The remaining 16 bits are CSPRNG-initialized sequence numbers.\n\n```txt\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n|0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n|0|                     timestamp (31 bits)                     |\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n|      timestamp (16 bits)      |   random+sequence (16 bits)   |\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n```\n\n## Limitations\n\n- Timestamps support years from 1970 to approx. 6429. To verify this, you can follow the formula *1970 + (2^47 − 1) / 1000 / (3600 * 24) / 365.25*\n\n- If several ZIDs are generated with the same millisecond timestamp, knowing one of them will allow you to discover the others due to linearly increasing sequence numbers. Otherwise, guessing ZID values is difficult (but not impossible) due to the millisecond precision of the timestamp and the additional 16 bits of entropy. Do not rely on ZIDs alone for your security!\n\n- You can generate up to 65,536 ZIDs within the same millisecond timestamp on a single machine. With two separate machines, you will generate on average 16,384 ZIDs each before a collision occurs within the same millisecond timestamp. With three separate machines, the average number is 10,240 ZIDs each.\n\n- ZIDs are not strictly increasing within the same millisecond timestamp due to the possible sequence number overflow.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaczero%2Fzid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzaczero%2Fzid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaczero%2Fzid/lists"}