百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
H

hashids-python

> 编程语言
开源

在 Python 中实现 hashids (http://hashids.org) 兼容 Python 2 和 Python 3

1.4K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

在 Python 中实现 hashids (http://hashids.org) 兼容 Python 2 和 Python 3

========================== hashids for Python 2.7 和 3 ===========================

Python 的 JavaScript hashids 实现的一个移植。它从一个或多个数字生成类似 YouTube 的哈希值。当您不希望将数据库 ID 向用户公开时,请使用 hashids。网站:http://www.hashids.org/

===================== hashids/JavaScript hashids/Python ----------------- -------------- v0.1.x v0.8.x v0.3.x+ v1.0.2+

JavaScript 实现在 0.1.x 和 0.3.x 版本中产生不同的哈希值。为了兼容旧版 0.1.x,请从 pip 安装 hashids 0.8.4,否则请安装最新的 hashids。 安装

从 PyPI 安装模块,例如使用 pip: .. 代码:: bash pip 安装 hashids pip install hashids==0.8.4 # 与 hashids.js 0.1.x 兼容 运行测试

测试使用 pytest <http://pytest.org/latest/>_. pytest 模块必须安装。

.. 代码:: bash Python -m pytest 用法

从「hashids」模块导入构造函数: .. 代码:: Python 从 hashids 中导入 Hashids hashids = Hashids() 基本用法

编码单个整数: .. 代码:: Python hashid = hashids.encode(123) # 'Mj3' 解码哈希: .. 代码:: Python ints = hashids.decode('xoz') # (456,) 要编码多个整数,请一次传递所有整数: .. 代码:: Python hashid = hashids.encode(123, 456, 789) # 'El3fkRIo3' 解码的方式是一样的: .. 代码:: Python ints = hashids.decode('1B8UvJfXm') # (517, 729, 185) 使用自定义盐

Hashids 支持通过接受盐值来生成盐化哈希。如果您不希望他人解码您的哈希,请向构造函数提供一个唯一字符串。

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Python

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言