Skip to main content

Generate Pydantic models for your Python package functions 🐶

Project description

🐶 mcpup

uv pdm-managed PyPI Supported Python versions License

Automatically generate Pydantic models for all functions in a Python package.

Features

  • Automatic Function Discovery: Scans all modules in a package to find functions
  • Pydantic Model Generation: Creates Pydantic models for function parameters using pydantic-function-models
  • Validation: Generated models perform validation according to type hints
  • Package Structure Preservation: Maintains the original package's module structure
  • Optional uv Integration: Can install packages on-the-fly with uv

Installation

# Install with pip
pip install mcpup

# Or with uv
uv pip install mcpup

Requirements

  • Python 3.10+
  • uv (recommended)

Command Line Usage

Generate Pydantic models for all functions in a package:

mcpup package_name

Options:

--output, -o DIRECTORY       Directory to save generated models [default: ./mcpup_models]
--install, -i                Install the package using uv before generating models
--include-private            Include private functions (starting with underscore)
--module, -m TEXT            Specific modules to include (can be used multiple times)
--help                       Show help message and exit

Examples

Generate models for all functions in the polars package:

mcpup polars

Generate models only for specific modules:

mcpup polars --module dataframe --module series

Install the package first, then generate models:

mcpup some-package --install

Include private functions:

mcpup mypackage --include-private

Programmatic Usage

You can also use mcpup programmatically:

from mcpup.scanner import scan_package
from mcpup.generator import generate_models
from pathlib import Path

# Scan a package for functions
functions = scan_package("mypackage", include_private=False)

# Generate models
output_path = Path("./models")
generate_models(functions, output_path)

Using Generated Models

After generating models, you can use them to validate function arguments:

# Import the generated model
from mcpup_models.mypackage.mymodule import MyFunction

# Validate function arguments
valid_args = MyFunction.model.model_validate({
    "arg1": "value",
    "arg2": 123
})

# Call the function with validated arguments
from mypackage.mymodule import my_function
result = my_function(**valid_args.model_dump(exclude_unset=True))

Contributing

Contributions welcome!

  1. Issues & Discussions: Please open a GitHub issue or discussion for bugs, feature requests, or questions.
  2. Pull Requests: PRs are welcome!
    • Install the dev extra with pip install -e ".[dev]"
    • Run tests with pytest
    • Include updates to docs or examples if relevant

License

This project is licensed under the MIT License.

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

mcpup-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

mcpup-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file mcpup-0.1.0.tar.gz.

File metadata

  • Download URL: mcpup-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.3 CPython/3.12.6 Linux/5.15.0-125-generic

File hashes

Hashes for mcpup-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e1294f2cfb9462b837df5b936ca267a1113f5b05830b469a5324c6ce83fd7f19
MD5 04d1c120147e1052c4477823645965af
BLAKE2b-256 6819dc1689a33a146748becd9afbeb973140b3ffe7fcf05fb44c5738df55c32a

See more details on using hashes here.

File details

Details for the file mcpup-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mcpup-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.3 CPython/3.12.6 Linux/5.15.0-125-generic

File hashes

Hashes for mcpup-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f6f330953f9e38eba5d78110c56c20dc9a11594aaa280d0fe6544dcfc56e2e0
MD5 78efe106d68f1e76d61361bdd2757ee3
BLAKE2b-256 fc8fc9d566a2c353e6342df3d398ce88a8a6d99ecf76c10aa289632f6116c825

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