Metadata-Version: 2.5
Name: ulidx
Version: 0.0.3
Summary: ULID 的生成与转换：按时间可排序、可单调、线程安全。
Project-URL: Homepage, https://pypi.org/project/ulidx/
Author-email: lqxnjk <lqxnjk@qq.com>
License: MIT
License-File: LICENSE
Keywords: id,identifier,monotonic,sortable,ulid,uuid
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# ulidx

[English](#english) | 中文

ULID 的生成与转换：按时间可排序、可单调、线程安全。

## 安装

```console
pip install ulidx
```

## 用法

```python
from ulidx import Ulid

Ulid.generate()                       # '01M5K7Y6ZR56XPB757MMHC9ERD'
Ulid.generate(n_monotonic=True)       # 同毫秒内严格递增
Ulid.generate_batch(1000)

value = Ulid.generate()
Ulid.to_timestamp(value)              # epoch 秒
Ulid.to_time(value)                   # UTC+8 的 datetime
Ulid.by_bytes(Ulid.to_bytes(value))   # 往返
Ulid.from_uuid(Ulid.to_uuid(value))
```

## 说明

26 字符 Crockford base32，无连字符。`n_monotonic=True` 时单调状态按线程隔离，同一线程同一毫秒内生成的 ULID 严格递增，批量建 ID 也不会乱序。可双向转换 UUID、原始 16 字节与时间戳。

## 许可证

MIT

---

<a id="english"></a>
## English

ULID generation and conversion: sortable, monotonic, thread-safe.

## Install

```console
pip install ulidx
```

## Usage

```python
from ulidx import Ulid

Ulid.generate()                       # '01M5K7Y6ZR56XPB757MMHC9ERD'
Ulid.generate(n_monotonic=True)       # 同毫秒内严格递增
Ulid.generate_batch(1000)

value = Ulid.generate()
Ulid.to_timestamp(value)              # epoch 秒
Ulid.to_time(value)                   # UTC+8 的 datetime
Ulid.by_bytes(Ulid.to_bytes(value))   # 往返
Ulid.from_uuid(Ulid.to_uuid(value))
```

## Notes

26 Crockford base32 characters, no hyphens. With `n_monotonic=True` the generator state is per thread, so ULIDs created in the same millisecond strictly increase. Converts both ways to `uuid.UUID`, raw 16 bytes and timestamps.

## License

MIT
