{"id":18335682,"url":"https://github.com/svix/python-ksuid","last_synced_at":"2025-04-05T15:05:53.033Z","repository":{"id":47695996,"uuid":"370467551","full_name":"svix/python-ksuid","owner":"svix","description":"A pure-Python KSUID implementation ","archived":false,"fork":false,"pushed_at":"2024-10-28T13:24:22.000Z","size":89,"stargazers_count":139,"open_issues_count":2,"forks_count":12,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T14:07:02.441Z","etag":null,"topics":["coordination","distributed","ksuid","python","svix","ulid","unique-id","uuid"],"latest_commit_sha":null,"homepage":"https://www.svix.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/svix.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","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":"2021-05-24T19:46:19.000Z","updated_at":"2025-02-11T20:24:09.000Z","dependencies_parsed_at":"2024-06-19T00:09:43.404Z","dependency_job_id":"db63cbf6-1099-44bc-ba61-a230756c5b2a","html_url":"https://github.com/svix/python-ksuid","commit_stats":null,"previous_names":["svixhq/python-ksuid"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svix%2Fpython-ksuid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svix%2Fpython-ksuid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svix%2Fpython-ksuid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svix%2Fpython-ksuid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svix","download_url":"https://codeload.github.com/svix/python-ksuid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247353731,"owners_count":20925329,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["coordination","distributed","ksuid","python","svix","ulid","unique-id","uuid"],"created_at":"2024-11-05T20:04:01.244Z","updated_at":"2025-04-05T15:05:53.008Z","avatar_url":"https://github.com/svix.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003ca href=\"https://www.svix.com\"\u003e\n    \u003cimg width=\"120\" src=\"https://avatars.githubusercontent.com/u/80175132?s=200\u0026v=4\" /\u003e\n    \u003cp align=\"center\"\u003eSvix - Webhooks as a service\u003c/p\u003e\n  \u003c/a\u003e\n\u003c/h1\u003e\n\n# Svix-KSUID (Python)\n\n![API-Lint](https://github.com/svixhq/python-ksuid/workflows/lint/badge.svg)\n![Frontend-Lint](https://github.com/svixhq/python-ksuid/workflows/test/badge.svg)\n![GitHub tag](https://img.shields.io/github/tag/svixhq/python-ksuid.svg)\n[![PyPI](https://img.shields.io/pypi/v/svix-ksuid.svg)](https://pypi.python.org/pypi/svix-ksuid/)\n[![Join our slack](https://img.shields.io/badge/Slack-join%20the%20community-blue?logo=slack\u0026style=social)](https://www.svix.com/slack/)\n\nThis library is inspired by [Segment's KSUID](https://segment.com/blog/a-brief-history-of-the-uuid/) implementation:\nhttps://github.com/segmentio/ksuid\n\nFor the Rust version, please check out https://github.com/svix/rust-ksuid\n\n## What is a ksuid?\n\nA ksuid is a K sorted UID. In other words, a KSUID also stores a date component, so that ksuids can be approximately \nsorted based on the time they were created. \n\nRead more [here](https://segment.com/blog/a-brief-history-of-the-uuid/).\n\n## Usage\n\n```\npip install svix-ksuid\n```\n\n```python\nfrom ksuid import Ksuid\n\nksuid = Ksuid()\n```\n\n### Higher timestamp accuracy mode\n\nKsuids have a 1 second accuracy which is not sufficient for all use-cases. That's why this library exposes a higher accuracy mode which supports accuracy of up to 4ms.\n\nIt's fully compatible with normal ksuids, in fact, it outputs valid ksuids. The difference is that it sacrifices one byte of the random payload in favor of this accuracy.\n\nThe code too is fully compatible:\n\n```\npip install svix-ksuid\n```\n\n```python\nfrom ksuid import KsuidMs\n\nksuid = KsuidMs()\n```\n\n## Examples\n\n### Default ksuid\n\nGenerate a ksuid without passing a specific datetime\n\n```python\nIn [1]: from ksuid import Ksuid\n\nIn [2]: ksuid = Ksuid()\n\nIn [3]: f\"Base62: {ksuid}\"\nOut[3]: 'Base62: 1srOrx2ZWZBpBUvZwXKQmoEYga2'\n\nIn [4]: f\"Bytes: {bytes(ksuid)}\"\nOut[4]: \"Bytes: b'\\\\r5\\\\xc43\\\\xe1\\\\x93\u003e7\\\\xf2up\\\\x87c\\\\xad\\\\xc7tZ\\\\xf5\\\\xe7\\\\xf2'\"\n\nIn [5]: f\"Datetime: {ksuid.datetime}\"\nOut[5]: 'Datetime: 2021-05-21 14:04:03'\n\nIn [6]: f\"Timestamp: {ksuid.timestamp}\"\nOut[6]: 'Timestamp: 1621627443'\n\nIn [7]: f\"Payload: {ksuid.payload}\"\nOut[7]: \"Payload: b'\\\\xe1\\\\x93\u003e7\\\\xf2up\\\\x87c\\\\xad\\\\xc7tZ\\\\xf5\\\\xe7\\\\xf2'\"\n```\n\n### ksuid from datetime\n\n```python\nIn [1]: datetime = datetime(year=2021, month=5, day=19, hour=1, minute=1, second=1, microsecond=1)\n\nIn [2]: datetime\nOut[2]: datetime.datetime(2021, 5, 19, 1, 1, 1, 1)\n\nIn [3]: ksuid = Ksuid(datetime)\n\nIn [4]: ksuid.datetime\nOut[4]: datetime.datetime(2021, 5, 19, 1, 1, 1)\n\nIn [5]: ksuid.timestamp\nOut[5]: 1621407661\n```\n\n### ksuid from base62\n\n```python\nIn [1]: ksuid = Ksuid()\n\nIn [2]: ksuid.timestamp\nOut[2]: 1621634852\n\nIn [3]: f\"Base62: {ksuid}\"\nOut[3]: 'Base62: 1srdszO8Xy2cR6CnARnvxCfRmK4'\n\nIn [4]: ksuid_from_base62 = Ksuid.from_base62(\"1srdszO8Xy2cR6CnARnvxCfRmK4\")\n\nIn [5]: ksuid_from_base62.timestamp\nOut[5]: 1621634852\n```\n\n### ksuid from bytes\n\n```python\nIn [1]: ksuid = Ksuid()\n\nIn [2]: ksuid_from_bytes = ksuid.from_bytes(bytes(ksuid))\n\nIn [3]: f\"ksuid: {ksuid}, ksuid_from_bytes: {ksuid_from_bytes}\"\nOut[3]: 'ksuid: 1sreAHoz6myPhXghsOdVBoec3Vr, ksuid_from_bytes: 1sreAHoz6myPhXghsOdVBoec3Vr'\n\nIn [4]: ksuid == ksuid_from_bytes\nOut[4]: True\n```\n\n### Compare ksuid(s)\n\n```python\nIn [1]: ksuid_1 = Ksuid()\n\nIn [2]: ksuid_2 = Ksuid.from_bytes(bytes(ksuid_1))\n\nIn [3]: f\"ksuid_1: {ksuid_1}, ksuid_2: {ksuid_2}\"\nOut[3]: 'ksuid_1: 1sreAHoz6myPhXghsOdVBoec3Vr, ksuid_2: 1sreAHoz6myPhXghsOdVBoec3Vr'\n\nIn [4]: ksuid_1 == ksuid_2\nOut[4]: True\n\nIn [5]: ksuid_1\nOut[5]: 1tM9eRSTrHIrrH5SMEW24rtvIOF\n\nIn [6]: ksuid_2\nOut[6]: 1tM9eRSTrHIrrH5SMEW24rtvIOF\n```\n\n\n### Order of ksuid(s)\n\n```python\nIn [1]: ksuid_1 = Ksuid()\n\nIn [2]: ksuid_1.timestamp\nOut[2]: 1621963256\n\nIn [3]: ksuid_2 = Ksuid()\n\nIn [4]: ksuid_2.timestamp\nOut[4]: 1621963266\n\nIn [5]: ksuid_1 \u003c ksuid_2\nOut[5]: True\n\nIn [6]: ksuid_1 \u003c= ksuid_2\nOut[6]: True\n\nIn [7]: ksuid_1 \u003e= ksuid_2\nOut[7]: False\n\nIn [8]: ksuid_1 \u003e ksuid_2\nOut[8]: False\n```\n\n### License\n\nksuid source code is available under an MIT [License](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvix%2Fpython-ksuid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvix%2Fpython-ksuid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvix%2Fpython-ksuid/lists"}