hashids-python: Generate YouTube-like Hashes from Numbers

This repository profile is provided by osrepos.com, an open source repository discovery platform.

hashids-python: Generate YouTube-like Hashes from Numbers

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.

Repository Information

Analyzed by OSRepos on July 31, 2026

Topics

Click on any tag to explore related repositories

Use at your own risk

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.

Introduction

`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.

Installation

Installing `hashids-python` is straightforward using pip:

pip install hashids

For compatibility with older `hashids.js 0.1.x` implementations, you can install a specific version:

pip install hashids==0.8.4

Examples

Here are some common ways to use `hashids-python`:

Basic Usage

Import the `Hashids` constructor and encode/decode integers:

from hashids import Hashids
hashids = Hashids()

# Encode a single integer
hashid = hashids.encode(123) # 'Mj3'
print(f"Encoded 123: {hashid}")

# Decode a hash
ints = hashids.decode('xoz') # (456,)
print(f"Decoded 'xoz': {ints}")

# Encode several integers
hashid_multi = hashids.encode(123, 456, 789) # 'El3fkRIo3'
print(f"Encoded 123, 456, 789: {hashid_multi}")

# Decode multiple integers
ints_multi = hashids.decode('1B8UvJfXm') # (517, 729, 185)
print(f"Decoded '1B8UvJfXm': {ints_multi}")

Using A Custom Salt

Adding a unique salt enhances the randomness and makes your hashes harder to guess:

hashids_salt1 = Hashids(salt='this is my salt 1')
hashid_salt1 = hashids_salt1.encode(123) # 'nVB'
print(f"Encoded 123 with salt 1: {hashid_salt1}")

hashids_salt2 = Hashids(salt='this is my salt 2')
hashid_salt2 = hashids_salt2.encode(123) # 'ojK'
print(f"Encoded 123 with salt 2: {hashid_salt2}")

A salt string between 6 and 32 characters provides decent randomization.

Controlling Hash Length

You can specify a minimum hash length to obfuscate the magnitude of the underlying integer:

hashids_min_len = Hashids(min_length=16)
hashid_min_len = hashids_min_len.encode(1) # '4q2VolejRejNmGQB'
print(f"Encoded 1 with min_length 16: {hashid_min_len}")

Using A Custom Alphabet

Customize the characters used in your hashes. For example, to use only lowercase letters:

hashids_alphabet = Hashids(alphabet='abcdefghijklmnopqrstuvwxyz')
hashid_alphabet = hashids_alphabet.encode(123456789) # 'kekmyzyk'
print(f"Encoded 123456789 with custom alphabet: {hashid_alphabet}")

A custom alphabet must contain at least 16 characters.

Why Use hashids-python?

`hashids-python` offers several compelling reasons for its use in applications:

  • ID Obfuscation: It effectively hides your database IDs, preventing users from inferring information about your data structure or enumerating records.
  • Unguessable Hashes: The algorithm is designed to produce unguessable and unpredictable hashes, even for sequential or repeating numbers, enhancing privacy.
  • Readability and Safety: It intelligently avoids generating common English curse words, making the hashes suitable for public display, such as in URLs.
  • Flexibility: With options for custom salts, minimum hash lengths, and custom alphabets, you have fine-grained control over the generated hashes.
  • Cross-Platform Compatibility: Being a port of the JavaScript `hashids` library, it allows for consistent ID generation across different parts of your tech stack.

While `hashids-python` excels at obfuscation, it's important to remember that it is not designed or tested for cryptographic security purposes.

Links

Related repositories

Similar repositories that may be relevant next.

A-MEM: Self-Evolving Memory for Coding Agents

A-MEM: Self-Evolving Memory for Coding Agents

August 17, 2026

A-MEM is an innovative self-evolving memory system designed for coding agents, organizing knowledge into a dynamic Zettelkasten-style graph. It allows memories to evolve and connect over time, enhancing an agent's ability to recall and utilize information effectively. This system offers both semantic and structural search capabilities for a richer knowledge base.

PythonAILLM
Agent Sandbox: Secure Local Development for AI Coding Agents

Agent Sandbox: Secure Local Development for AI Coding Agents

August 17, 2026

Agent Sandbox provides a robust and secure local development environment specifically designed for collaborating with AI coding agents. It ensures minimal filesystem access, configurable network egress policies, and secure secret injection, protecting your local machine from potentially risky agent operations. This project supports various AI agents and integrates seamlessly with both CLI and popular IDE devcontainer setups.

agent-harnessagent-sandboxagents
AMD Skills: Empowering AI Agents with AMD's Optimized Software Stack

AMD Skills: Empowering AI Agents with AMD's Optimized Software Stack

August 16, 2026

AMD Skills is the official catalog of AI agent skills from AMD, designed to empower AI agents with optimized software for AMD hardware. This repository provides knowledge, scripts, and conventions for working with AMD's stack, enabling seamless integration with major coding agents like Cursor, Claude Code, OpenAI Codex, and Gemini CLI.

PythonAI AgentsMachine Learning
agent-tackle-box: A Terminal Debugger for LangGraph & LangChain Agents

agent-tackle-box: A Terminal Debugger for LangGraph & LangChain Agents

August 15, 2026

agent-tackle-box is a comprehensive toolkit for developing AI agents, featuring the powerful `agent-debugger`. This terminal debugger provides deep insights into LangGraph and LangChain agents. It allows developers to inspect state, monitor tool calls, and step through Python code, all within a unified Textual UI.

agent-debuggerai-agentslangchain

Source repository

Open the original repository on GitHub.

11 counted GitHub visits

View on GitHub
OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️