A parameter management toolkit for Python
Project description
🚀 特性
- 智能参数管理:支持类型检查、范围验证和默认值配置
- 多格式支持:自动解析 JSON/YAML/TOML 配置文件
- CLI 集成:通过装饰器快速构建命令行接口
- 环境变量绑定:支持
.env文件和环境变量注入 - 验证引擎:内置正则表达式和自定义验证规则
- 类型提示:完整的 Python 类型注解支持
📦 安装
pip install paramkit
或安装开发版本:
pip install git+https://github.com/yourusername/paramkit.git
🛠️ 快速开始
基本用法
class DemoView(APIView):
"""
Demo view class to demonstrate parameter validation.
"""
@apiassert(
P('name', typ=str, gt=2, le=3, opts=('cgq', 'b'), must=False),
P('age', typ=int, ge=2, le=100),
P('addr', typ=dict, le=10, ge=2),
P('hobbies', typ=list, ge=1, le=16),
P('addr.school.teacher', typ=str, ge=2, le=6, opts=('xz', 'ydy')),
)
def view_func(self, request):
"""
Example view function to demonstrate parameter validation.
:param request: The request object
"""
print(request)
CLI 集成
from paramkit import cli_command
@cli_command
def main(
username: str = Param(help="User login name"),
retries: int = Param(default=3, min=1)
):
print(f"Connecting as {username} (max {retries} retries)")
运行程序:
python app.py --username admin --retries 5
📚 文档
完整文档请访问:
https://paramkit.readthedocs.io
🧪 测试覆盖率
-------------------------- coverage: --------------------------
Name Stmts Miss Cover
--------------------------------------------
paramkit/__init__.py 5 0 100%
paramkit/core.py 142 2 98%
paramkit/cli.py 89 1 99%
--------------------------------------------
TOTAL 236 3 98%
🤝 贡献指南
欢迎通过 Issue 或 PR 参与贡献!
请先阅读 CONTRIBUTING.md
- Fork 项目仓库
- 创建特性分支 (
git checkout -b feature/amazing-feature) - 提交更改 (
git commit -m 'Add some amazing feature') - 推送分支 (
git push origin feature/amazing-feature) - 创建 Pull Request
📄 许可证
本项目采用 MIT License
📬 联系方式
作者:Dylan
邮箱:cgq2012516@gmail.com
## 🎨 项目架构
```mermaid
graph TD
A[ParamKit] --> B[Core Engine]
A --> C[CLI Interface]
A --> D[File Loaders]
B --> E[Validation]
B --> F[Type Conversion]
D --> G[JSON/YAML/TOML]
C --> H[Argparse Integration]
E --> I[Regex Validation]
E --> J[Custom Validators]
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
paramkit-0.2.8.tar.gz
(735.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
paramkit-0.2.8-py3-none-any.whl
(739.8 kB
view details)
File details
Details for the file paramkit-0.2.8.tar.gz.
File metadata
- Download URL: paramkit-0.2.8.tar.gz
- Upload date:
- Size: 735.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48c1e5399be032f8ee2b8fe0e22136d20ecb3d19b13978abf6304d308467902a
|
|
| MD5 |
a12119396049c2610bc32f67ca9e2b98
|
|
| BLAKE2b-256 |
3407aac5e4463cf48ed329e5cf1fc0628cbdc767a7448773a2551e2676544462
|
File details
Details for the file paramkit-0.2.8-py3-none-any.whl.
File metadata
- Download URL: paramkit-0.2.8-py3-none-any.whl
- Upload date:
- Size: 739.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a97eedb74ae9a4be32c7e3d15d55f25103c54db22511f9fa608534f0502abee
|
|
| MD5 |
5d25cf2dfd596f5eb4d0b0c21cbdf2e6
|
|
| BLAKE2b-256 |
b949e30b025e695e28397c384ee0ff12f3e998e0e70ee0fae89b4e2724f4464b
|