Skip to main content

ParamKit

PyPI Version Python Versions License Documentation

🚀 特性

  • 智能参数管理:支持类型检查、范围验证和默认值配置
  • 多格式支持:自动解析 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

  1. Fork 项目仓库
  2. 创建特性分支 (git checkout -b feature/amazing-feature)
  3. 提交更改 (git commit -m 'Add some amazing feature')
  4. 推送分支 (git push origin feature/amazing-feature)
  5. 创建 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]

Metadata

Release files for paramkit 0.2.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for paramkit 0.2.9
File Size Uploaded
paramkit-0.2.9.tar.gz 724.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for paramkit 0.2.9
File Interpreter ABI Platform
paramkit-0.2.9-py3-none-any.whl Python 3 none any Details

Total release size: 1.5 MB

Release files / paramkit-0.2.9.tar.gz

Download URL paramkit-0.2.9.tar.gz
Size 724.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e02ac423ef1c3e85f12b2c6eb4208460db3b2db60dc9c7465165cb02a98a904a
BLAKE2b-256 checksum
How to use checksums
a7309655934be0e2d93c7f07c73417bbbe4a6089af69bf3dd197b2e9e8940d0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Release files / paramkit-0.2.9-py3-none-any.whl

Download URL paramkit-0.2.9-py3-none-any.whl
Size 728.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7f3d1d564c6e16d5c65c3920d2a275224130aa382fda68507696a83c4b8797e
BLAKE2b-256 checksum
How to use checksums
81571e28b5ffaddcbbcc6c753a2e37a7c20720fb73a8f2712ff101cb5814acde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Release history Release notifications | RSS feed

This release

0.2.9 This release

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page