{"name":"hashids-python: Generate YouTube-like Hashes from Numbers","description":"`hashids-python` is a Python implementation of the `hashids` library, designed to generate short, unique, YouTube-like hashes from one or many numbers. It's ideal for obfuscating database IDs without exposing their original values to users. This library ensures compatibility across Python 2 and 3, offering a flexible way to handle public-facing identifiers.","github":"https://github.com/davidaurelio/hashids-python","url":"https://osrepos.com/repo/davidaurelio-hashids-python","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/davidaurelio-hashids-python","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/davidaurelio-hashids-python.md","json":"https://osrepos.com/repo/davidaurelio-hashids-python.json","topics":["Python","Hashing","ID Obfuscation","Web Development","Utilities","Open Source"],"keywords":["Python","Hashing","ID Obfuscation","Web Development","Utilities","Open Source"],"stars":null,"summary":"`hashids-python` is a Python implementation of the `hashids` library, designed to generate short, unique, YouTube-like hashes from one or many numbers. It's ideal for obfuscating database IDs without exposing their original values to users. This library ensures compatibility across Python 2 and 3, offering a flexible way to handle public-facing identifiers.","content":"## Introduction\n\n`hashids-python` is a robust Python implementation of the popular `hashids` library, designed to generate short, unique, YouTube-like hashes from one or many numbers. Its primary purpose is to obfuscate database IDs, preventing the exposure of their original numeric values to users in public-facing URLs or APIs. This library ensures broad compatibility, supporting Python 2.7 and Python 3.5-3.8, including PyPy environments. It provides a flexible and secure method for handling identifiers when direct numeric exposure is undesirable.\n\n## Installation\n\nInstalling `hashids-python` is straightforward using pip:\n\nbash\npip install hashids\n\n\nFor compatibility with older `hashids.js 0.1.x` implementations, you can install a specific version:\n\nbash\npip install hashids==0.8.4\n\n\n## Examples\n\nHere are some common ways to use `hashids-python`:\n\n### Basic Usage\n\nImport the `Hashids` constructor and encode/decode integers:\n\npython\nfrom hashids import Hashids\nhashids = Hashids()\n\n# Encode a single integer\nhashid = hashids.encode(123) # 'Mj3'\nprint(f\"Encoded 123: {hashid}\")\n\n# Decode a hash\nints = hashids.decode('xoz') # (456,)\nprint(f\"Decoded 'xoz': {ints}\")\n\n# Encode several integers\nhashid_multi = hashids.encode(123, 456, 789) # 'El3fkRIo3'\nprint(f\"Encoded 123, 456, 789: {hashid_multi}\")\n\n# Decode multiple integers\nints_multi = hashids.decode('1B8UvJfXm') # (517, 729, 185)\nprint(f\"Decoded '1B8UvJfXm': {ints_multi}\")\n\n\n### Using A Custom Salt\n\nAdding a unique salt enhances the randomness and makes your hashes harder to guess:\n\npython\nhashids_salt1 = Hashids(salt='this is my salt 1')\nhashid_salt1 = hashids_salt1.encode(123) # 'nVB'\nprint(f\"Encoded 123 with salt 1: {hashid_salt1}\")\n\nhashids_salt2 = Hashids(salt='this is my salt 2')\nhashid_salt2 = hashids_salt2.encode(123) # 'ojK'\nprint(f\"Encoded 123 with salt 2: {hashid_salt2}\")\n\n\nA salt string between 6 and 32 characters provides decent randomization.\n\n### Controlling Hash Length\n\nYou can specify a minimum hash length to obfuscate the magnitude of the underlying integer:\n\npython\nhashids_min_len = Hashids(min_length=16)\nhashid_min_len = hashids_min_len.encode(1) # '4q2VolejRejNmGQB'\nprint(f\"Encoded 1 with min_length 16: {hashid_min_len}\")\n\n\n### Using A Custom Alphabet\n\nCustomize the characters used in your hashes. For example, to use only lowercase letters:\n\npython\nhashids_alphabet = Hashids(alphabet='abcdefghijklmnopqrstuvwxyz')\nhashid_alphabet = hashids_alphabet.encode(123456789) # 'kekmyzyk'\nprint(f\"Encoded 123456789 with custom alphabet: {hashid_alphabet}\")\n\n\nA custom alphabet must contain at least 16 characters.\n\n## Why Use hashids-python?\n\n`hashids-python` offers several compelling reasons for its use in applications:\n\n*   **ID Obfuscation**: It effectively hides your database IDs, preventing users from inferring information about your data structure or enumerating records.\n*   **Unguessable Hashes**: The algorithm is designed to produce unguessable and unpredictable hashes, even for sequential or repeating numbers, enhancing privacy.\n*   **Readability and Safety**: It intelligently avoids generating common English curse words, making the hashes suitable for public display, such as in URLs.\n*   **Flexibility**: With options for custom salts, minimum hash lengths, and custom alphabets, you have fine-grained control over the generated hashes.\n*   **Cross-Platform Compatibility**: Being a port of the JavaScript `hashids` library, it allows for consistent ID generation across different parts of your tech stack.\n\nWhile `hashids-python` excels at obfuscation, it's important to remember that it is not designed or tested for cryptographic security purposes.\n\n## Links\n\n*   **GitHub Repository**: <a href=\"https://github.com/davidaurelio/hashids-python\" target=\"_blank\">davidaurelio/hashids-python</a>\n*   **Official hashids Website**: <a href=\"http://hashids.org\" target=\"_blank\">hashids.org</a>","metrics":{"detailViews":1,"githubClicks":1},"dates":{"published":null,"modified":"2026-07-31T08:31:58.000Z"}}