{"id":16420830,"url":"https://github.com/jaddison/django-prefix-id","last_synced_at":"2025-06-14T23:02:59.135Z","repository":{"id":200066638,"uuid":"703274040","full_name":"jaddison/django-prefix-id","owner":"jaddison","description":"A modern Django model ID field, enabling prefixed Stripe-like IDs. Base62 encoding UUID values.","archived":false,"fork":false,"pushed_at":"2023-10-14T01:11:50.000Z","size":11,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-07T04:36:48.175Z","etag":null,"topics":["base62","django","model-field","uuid"],"latest_commit_sha":null,"homepage":"https://github.com/jaddison/django-prefix-id","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/jaddison.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":"2023-10-11T00:02:12.000Z","updated_at":"2025-02-27T19:22:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"86a2c4ff-018c-4f0a-86c7-78e789f6a0fb","html_url":"https://github.com/jaddison/django-prefix-id","commit_stats":null,"previous_names":["jaddison/django-prefix-id"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaddison%2Fdjango-prefix-id","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaddison%2Fdjango-prefix-id/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaddison%2Fdjango-prefix-id/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaddison%2Fdjango-prefix-id/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaddison","download_url":"https://codeload.github.com/jaddison/django-prefix-id/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaddison%2Fdjango-prefix-id/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259144977,"owners_count":22811938,"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":["base62","django","model-field","uuid"],"created_at":"2024-10-11T07:29:16.802Z","updated_at":"2025-06-14T23:02:59.127Z","avatar_url":"https://github.com/jaddison.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Overview\n\n`django-prefix-id` is a simple package that contains a single Django model \nfield, `PrefixIDField`. `PrefixIDField` is\n- based on Django's `CharField`\n- allows using a prefix (recommended for context)\n  - enables some very interesting product usage and querying patterns \n- autogenerates a unique id by default (auto-including the prefix, if provided)\n  - uses `uuid.uuid4()` to generate a 128-bit integer, which is then \n    base62-encoded \n- auto-sets the `max_length` field property, factoring in the provided prefix length \n  and a known max length of 22 characters for a base62-encoded 128-bit integer\n\n**Why work with IDs like `7584358` or `'7fca5f1d-f867-4696-960b-e57274cc5647'` \nwhen you could have something swanky like `'user_4wr7jBDTEqVBCsXEih4zfP'`?**\n\nIf you already like to use UUIDs as IDs, you should use `django-prefix-id`! If you currently use\nautoincrementing IDs, you should also consider using `django-prefix-id`, from an obfuscation \npoint of view.\n\n### Installation\n\n```shell\n$ pip install django-prefix-id\n```\n\n### Usage\n```python\nfrom prefix_id import PrefixIDField\n\nclass Book(models.Model):\n    id = PrefixIDField(prefix=\"book\", primary_key=True)\n    title = models.CharField(max_length=100, blank=False)\n    ...\n```\n\nMake your migrations, as you normally would:\n```shell\n$ python manage.py makemigrations\n```\n\n### Development\n\n```shell\n$ pip -m venv venv\n$ source /venv/bin/activate\n$ pip install -r requirements.txt\n```\n\n### Testing\n\nManually run tests:\n```shell\n$ pytest\n```\n\nTest coverage is at 100%. To get test coverage output:\n```shell\n$ pytest --cov --cov-report html\n# OR\n$ pytest --cov\n```\n\nTo cover a breadth of likely usage scenarios, `tox` is the tool of \nchoice. It is set up with a matrix covering various combinations of \nPython versions 3.8 - 3.12 with Django 4.2 and 5.0.\n\nSee `tox.ini` to enable testing Django versions as far back as Django \n3.2 - tests pass across the board, but for simplicity only latest LTS \nDjango and other currently supported versions will be considered in \nscope.\n\nRun the test suite against all enabled versions:\n\n```shell\n$ tox\n```\n\n### Backstory and Inspiration\n\nStripe-like prefixed entity IDs have long been a topic of interest to me, \nand the improved user experience that they can provide. I'd gone through \na couple of iterations with FastAPI and Django - and thought I might as \nwell release something that I'm happy with sharing publicly.\n\nAbout 80% through this effort, I found yunojuno's \n[django-charid-field](https://github.com/yunojuno/django-charid-field/) \nproject, and took some further inspiration from it - so thanks to them! \n\n(It also appears we have other project interests in common!)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaddison%2Fdjango-prefix-id","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaddison%2Fdjango-prefix-id","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaddison%2Fdjango-prefix-id/lists"}