This is a tool for producing random data.
Project description
m-mock - 智能模拟数据生成库
m-mock是一个功能强大的Python模拟数据生成库,支持生成各种类型的随机数据,包括日期时间、数字、字符串、姓名、文本等。
功能特点
- 📅 日期时间:生成随机日期、时间、时间戳
- 🔢 数字类型:整数、浮点数、自然数
- 🔤 文本类型:中英文句子、段落、混合文本
- 👤 姓名生成:中英文姓名、姓氏、名字
- 🆔 标识符:UUID、自增ID、中国身份证号
- 🎲 随机选择:从列表中随机选取元素
- 🛠️ 易于扩展:支持自定义数据生成规则
安装
pip install m-mock
快速开始
基本使用
from m-mock import m_mock
# 生成随机日期
print(m_mock.mock("@date()")) # 输出: "2023-07-15"
# 生成随机中文姓名
print(m_mock.mock("@cname()")) # 输出: "张三"
# 生成随机浮点数
print(m_mock.mock("@float(1,100)")) # 输出: 56.78
高级用法
# 带参数的日期生成
print(m_mock.mock("@date('%Y年%m月%d日','+3d')")) # 输出: "2023年07月18日"
# 生成随机段落
print(m_mock.mock("@cparagraph(5,8)")) # 输出: "这是一个随机生成的中文段落..."
# 从列表中选择
print(m_mock.mock("@pick(['苹果','香蕉','橙子'])")) # 输出: "香蕉"
完整API参考
日期时间
| 表达式 | 描述 | 示例 |
|---|---|---|
@date() |
当前日期 | "2023-07-15" |
@date(format, interval) |
格式化日期 | @date('%Y/%m/%d','+1d') |
@datetime() |
当前日期时间 | "2023-07-15 14:30:00" |
@time() |
当前时间 | "14:30:00" |
@timestamp() |
时间戳(毫秒) | 1689409800000 |
@now(unit) |
指定单位时间 | @now('month') |
数字类型
| 表达式 | 描述 | 示例 |
|---|---|---|
@integer(min,max) |
随机整数 | @integer(1,100) → 42 |
@float(min,max,d_min,d_max) |
随机浮点数 | @float(0,1,2,4) → 0.75 |
@natural(min,max) |
自然数 | @natural(10,20) → 15 |
@boolean() |
布尔值 | True/False |
文本相关
| 表达式 | 描述 | 示例 |
|---|---|---|
@string(type,min,max) |
随机字符串 | @string('lower',5,10) → "abcdef" |
@character(type) |
随机字符 | @character('upper') → "A" |
@sentence(min,max) |
英文句子 | @sentence(5,10) → "This is a sentence." |
@csentence(min,max) |
中文句子 | @csentence(5,10) → "这是一个句子。" |
@paragraph(min,max) |
英文段落 | @paragraph(3,5) → "A paragraph..." |
@cparagraph(min,max) |
中文段落 | @cparagraph(3,5) → "这是一个段落..." |
@mix_sentence(min,max) |
混合文本 | @mix_sentence(5,10) → "Hello 世界 123" |
姓名相关
| 表达式 | 描述 | 示例 |
|---|---|---|
@name() |
英文姓名 | "John Smith" |
@cname() |
中文姓名 | "张三" |
@first() |
英文姓氏 | "Smith" |
@last() |
英文名字 | "John" |
@clast() |
中文姓氏 | "张" |
@cfirst(length) |
中文名字 | @cfirst(2) → "三丰" |
其他功能
| 表达式 | 描述 | 示例 |
|---|---|---|
@pick(list) |
从列表选择 | @pick(['A','B','C']) → "B" |
@increment(step) |
自增数字 | @increment(2) → "2", "4", "6"... |
@uuid() |
UUID生成 | "a1b2c3d4..." |
@id() |
中国身份证号 | "110105199003072316" |
贡献指南
欢迎贡献代码!请遵循以下步骤:
- Fork仓库
- 创建特性分支 (
git checkout -b feature/your-feature) - 提交更改 (
git commit -am 'Add some feature') - 推送到分支 (
git push origin feature/your-feature) - 创建Pull Request
许可证
本项目采用 MIT License 许可证。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
m_mock-1.3.9.tar.gz
(42.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
m_mock-1.3.9-py3-none-any.whl
(33.8 kB
view details)
File details
Details for the file m_mock-1.3.9.tar.gz.
File metadata
- Download URL: m_mock-1.3.9.tar.gz
- Upload date:
- Size: 42.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee850912899f02f140fcf7dd8e9851459174e9d613ecb34b7b9d0b4ffbb35503
|
|
| MD5 |
9f48934a7b65bd83414ca833bbd1d756
|
|
| BLAKE2b-256 |
8a746a07b2b0390b3ce5acdde57e1609768fa6f0401594047109e15a448e78e3
|
File details
Details for the file m_mock-1.3.9-py3-none-any.whl.
File metadata
- Download URL: m_mock-1.3.9-py3-none-any.whl
- Upload date:
- Size: 33.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f77e9e150a2c65c1f3e7ce61d35dd06ab27ec9243b280eff9cfc06888dfbb67
|
|
| MD5 |
4b54ab1f2fa26bc666e9bd31eefca79b
|
|
| BLAKE2b-256 |
1bd9b50ac7392b703b93322fd8bf6a361fa0288014486aa2f33171a67040672c
|