https://github.com/alumik/id-tool
Python ID 工具包
https://github.com/alumik/id-tool
idgenerator python
Last synced: 8 months ago
JSON representation
Python ID 工具包
- Host: GitHub
- URL: https://github.com/alumik/id-tool
- Owner: alumik
- License: mit
- Created: 2018-09-19T03:43:33.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2020-10-28T06:37:56.000Z (over 5 years ago)
- Last Synced: 2025-01-22T12:47:59.583Z (over 1 year ago)
- Topics: idgenerator, python
- Language: Python
- Homepage:
- Size: 23.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ID 工具包


[](https://github.com/AlumiK/id-tool/blob/main/LICENSE)
## 引入模块
```python
import idtool
```
## 构造参数
### idtool.IDGenerator
- `length: int = None`
等宽 ID 字符位数。为空表示不限制位数。
- `chars: typing.Sequence = None`
ID 字符序列(例如 ['1', '2', '3'] )。默认值为 ['0', '1', ..., '9', 'a', 'b', ..., 'z']。
- `initial: str = None`
初始 ID。
## 接口说明
### idtool.IDGenerator
- `idtool.IDGenerator.next() -> bool`
生成下一个 ID 并返回是否有进位。
- `idtool.IDGenerator.get_id() -> str`
返回当前 ID。
- `idtool.IDGenerator.set_id(new_id: str)`
设置当前 ID。
### idtool.IDManager
- `idtool.IDManager.add_id(generator: idtool.IDGenerator, auto_increase: bool = False)`
给 ID 管理器添加一个 ID 。 `auto_increase` 代表该位是否会由于低位进位而自动增长。
- `idtool.IDManager.add_separator(separator: str)`
给 ID 管理器添加一个 str 作为分隔符。
- `idtool.IDManager.next(index: int = None)`
对指定位置的 ID 进行进位。
- `idtool.IDManager.set_id(index: int, new_id: str)`
更改指定位置的 ID。
- `idtool.IDManager.get_id() -> str`
返回当前 ID。
## 异常
- `idtool.IDGenerator.DuplicateChars`
字符序列存在重复字符。
- `idtool.IDGenerator.IllegalIDFormat`
要设置的 ID 格式不正确。