Skip to main content

A parameter management toolkit for Python

Project description

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]

Project details


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.5.tar.gz (90.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

paramkit-0.2.5-py3-none-any.whl (93.3 kB view details)

Uploaded Python 3

File details

Details for the file paramkit-0.2.5.tar.gz.

File metadata

  • Download URL: paramkit-0.2.5.tar.gz
  • Upload date:
  • Size: 90.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for paramkit-0.2.5.tar.gz
Algorithm Hash digest
SHA256 063a79fe4620b3524021fa2f6ef3dd4e16f1ff5d6bf5b2ada0e9217b9bd1c8d1
MD5 5d50033dfe608f3860cdf8e71baf998b
BLAKE2b-256 ea8182f45f862376451a2b29457de2d36d7e2b7bd7f280f0eb685f67485d7cc6

See more details on using hashes here.

File details

Details for the file paramkit-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: paramkit-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 93.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for paramkit-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 39a4b63917770d66e37a5be2aae74718fa616979ea5124f613c57fdb6adc33b0
MD5 d6478f488fe81f3da84dcb0c9b0c9e83
BLAKE2b-256 71989f7f1034e6128604364f38abdad0aa314dfe895e5908a060095357a05a0f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page