Slim-ID: A Lightweight ID Generation Library for Python
下の方に日本語の説明があります
Overview
- This is a tool that automatically generates short IDs.
- It has a mechanism to avoid collisions with already generated IDs.
Features
- Specify the desired length for generated IDs (default is 5 characters)
- Automatically increases the length if the generated ID conflicts with existing IDs
- Specify the alphabet to use for the ID (default is URL-safe Base64, but hexadecimal can also be specified)
- Uses cryptographically secure random number generation internally, providing a degree of protection against attackers predicting the random number from timestamps, etc.
- Requires a user-defined function to determine if a generated ID conflicts with existing IDs. This function is expected to handle dictionary lookups or database queries, for example.
Usage Example
import sys
import slim_id
id_dic = {}
def exists(arg_id):
return (arg_id in id_dic)
# Generate an ID using Slim-ID
s_id = slim_id.gen(exists)
id_dic[s_id] = True
print(s_id)
# Generate an ID using Slim-ID with custom parameters
s_id = slim_id.gen(
exists, # Function to determine if an ID exists in the database
length = 7, # Base length (automatically increases if a collision occurs)
ab = "16", # Alphabet type (base64url... URL-safe Base64, 16... hexadecimal)
)
id_dic[s_id] = True
print(s_id)
Custom Alphabet for Generating Slim-ID
Users can now specify a custom character set for generating IDs, allowing for tailored ID generation to meet specific needs. When using a custom alphabet, provide a list of characters to be used.
import sys
import slim_id
id_dic = {}
def exists(arg_id):
return (arg_id in id_dic)
# Generate a basic Slim-ID
s_id = slim_id.gen(exists)
id_dic[s_id] = True
print(s_id)
# Generate a Slim-ID using a custom alphabet
s_id = slim_id.gen(
exists, # Function to check if the ID already exists in the database
length = 7, # Base length (will increase automatically if a collision occurs)
ab = list("0123456789"), # Custom alphabet
)
id_dic[s_id] = True
print(s_id)
With this feature, IDs are generated using the specified custom alphabet set. For example, in the code above, the generated IDs will consist only of numbers.
Here is the English translation of your document:
Usage from the Command Line
-
You can use the following command in the console:
-
If no argument is provided, the default length will be 30.
slim_id
- You can specify the length as an argument. (In the example below, the result will be 10 characters long)
slim_id 10
概要
- 短いIDを自動生成するツールです
- 生成済みIDとの衝突を回避する仕組みを持っています
特徴
- 生成されるIDの長さを指定可能(デフォルトは5文字)
- 生成されたIDが既存のIDと衝突する場合、長さが自動的に増える
- IDに使用するアルファベットを指定可能(デフォルトはURLセーフなBase64だが、16進数も指定できる)
- 内部で暗号学的に安全な乱数生成を使用しており、タイムスタンプなどから乱数を推定する攻撃者に対してある程度の保護を提供
- 生成されたIDが既存のIDと衝突しているかどうかを判断する関数をユーザーが定義する必要がある。この関数は、辞書の引当やDBの引き当てなどを処理することが想定されている。
import sys
import slim_id
id_dic = {}
def exists(arg_id):
return (arg_id in id_dic)
# Slim-IDを使用してIDを生成
s_id = slim_id.gen(exists)
id_dic[s_id] = True
print(s_id)
# カスタムパラメータを使用してSlim-IDでIDを生成
s_id = slim_id.gen(
exists, # IDがデータベースに存在するかどうかを判断する関数
length = 7, # 基本長(衝突が発生した場合、自動的に長くなります)
ab = "16", # アルファベットの種類(base64url... URLセーフな64進数、16... 16進数)
)
id_dic[s_id] = True
print(s_id)
カスタムアルファベット指定
ユーザーが任意の文字セットを指定してIDを生成できるようになりました。これにより、特定のニーズに応じたID生成が可能になります。 (カスタム指定の場合は、アルファベットの文字のリストを指定します。)
import sys
import slim_id
id_dic = {}
def exists(arg_id):
return (arg_id in id_dic)
# 基本的なSlim-IDの生成
s_id = slim_id.gen(exists)
id_dic[s_id] = True
print(s_id)
# カスタムアルファベットを使用してSlim-IDでIDを生成
s_id = slim_id.gen(
exists, # IDがデータベースに存在するかどうかを判断する関数
length = 7, # 基本長(衝突が発生した場合、自動的に長くなります)
ab = list("0123456789"), # カスタムアルファベットの種類
)
id_dic[s_id] = True
print(s_id)
これにより、指定されたカスタムアルファベットのセットからIDが生成されます。例えば、上記の例では数字のみを使用してIDが生成されます。
コマンドラインからの利用
-
コンソールで下記コマンドで利用できます
-
引数を省略した場合、長さは30になります。
slim_id
- 引数で長さを指定できます。 (下記の場合は10桁になる)
slim_id 10
Metadata
Release files for slim-id 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| slim-id-0.1.1.tar.gz | 4.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| slim_id-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.0 kB
Release files / slim-id-0.1.1.tar.gz
| Download URL | slim-id-0.1.1.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7936380b02bac5a298a0903519a519f5f710a35a0fdb73dcd8945ff6dec5d109
|
|
BLAKE2b-256 checksum How to use checksums |
bfee32b3bb03d8563de82472cf46cd8debdb0d531f0c710501510fc190f7056a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.3
|
Release files / slim_id-0.1.1-py3-none-any.whl
| Download URL | slim_id-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
36aa9dca4e22ed6191f8e1640efb5dbfeb88f439976043bdf456c5de6fd581e0
|
|
BLAKE2b-256 checksum How to use checksums |
a1ebde4af16bf42e831e1ddff27ba9306df7c9ffdc4d5cb06f3dd1dde146f6d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.3
|
Security for slim-id 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.