Python Best Practices Launchpad

by Acid-base

1 101 downloads Not rated yet MIT
GitHub

About

Python MCP server with CI/CD tooling and testability built-in

Details

License
MIT

Explore

REST API with FastAPI: Ready-to-use API with data validation using Pydantic models.
Docker & Docker Compose: Production-ready containerization with multi-stage builds.
uv for Dependency Management: Fast and efficient dependency resolution and virtual environment management.
ruff for Linting and Formatting: Enforces consistent code style, catches errors early, and provides auto-fixing capabilities.
mypy for Type Checking: Adds static typing to your Python code, preventing type-related errors.
pytest for Testing: Comprehensive test suite with unit, API, and integration tests.
pre-commit for Git Hooks: Automates code quality checks before every commit.
GitHub Actions Workflow: Ready-to-use CI pipeline for testing and quality assurance.

  • Dev Container Support: Included configuration for instant development in VS Code or GitHub Codespaces.

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Python Best Practices Launchpad
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

You can choose one of two approaches to set up this project:

Before cloning the repository, make sure you have Linuxbrew installed (or Homebrew on macOS).

1. Install WSL: Follow the official Microsoft instructions to install WSL and choose a Linux distribution (e.g., Ubuntu).

2. Open a Direct WSL Terminal:
Do NOT use wsl from a Windows terminal (like PowerShell or Command Prompt).
In VS Code: Open a new integrated terminal by clicking the "+" button on the terminals tab, and select your WSL distribution (e.g., "Ubuntu", "Debian") from the dropdown menu.
From Start Menu: Alternatively, launch your WSL distribution's terminal directly from the Windows Start Menu (e.g., "Ubuntu", "Debian").

All subsequent steps in this section must be executed within this direct WSL terminal.

3. Install Base Dependencies (Within WSL):

    sudo apt update && sudo apt install -y build-essential curl file git

4. Install Linuxbrew:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

5. Add Linuxbrew to PATH:
Add the following lines to your ~/.bashrc or ~/.zshrc (depending on your shell):
    export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
export MANPATH="/home/linuxbrew/.linuxbrew/share/man:$MANPATH"
export INFOPATH="/home/linuxbrew/.linuxbrew/share/info:$INFOPATH"

Then run source ~/.bashrc or source ~/.zshrc.
6. Install Python via Linuxbrew: brew install python

Once Linuxbrew (or Homebrew on macOS) and Python are installed, you can continue with the following steps:

1. Clone the Repository:

    git clone <repository_url>
cd <project_name>

2. Create and Activate Virtual Environment:

    uv venv

This command creates a virtual environment, if one does not exist already.

3. Install Dependencies:

     uv sync

This command installs all dependencies from your lock file (uv.lock), including development dependencies.

4. Install Git Hooks:

    pre-commit install

This command installs the pre-commit hooks that ensure formatting and linting happen automatically before each commit.

5. Create a lock file:

    uv lock

This command creates a lock file which locks all dependencies in the project to a known version.

The project's core configuration is located in the pyproject.toml file.

Project Metadata:
Basic project information like name, version, description, authors, etc.
Python version specified in requires-python
Dependencies:
Project's dependencies listed in the [project.dependencies array.
Development dependencies listed in the [project.optional-dependencies.dev] array, or you can add additional groups.

This file configures pre-commit, a tool that runs checks before each commit. It includes:

General-Purpose Hooks (pre-commit-hooks): Trailing whitespace removal, end-of-file newline enforcement, YAML validation, etc.
ruff Hook (astral-sh/ruff-pre-commit): Automatically fixes Ruff errors (ruff --fix).
black Hook (psf/black): Automatically reformats your code with the black formatter
mypy Hook (pre-commit/mirrors-mypy): Checks code for type errors with mypy

This file configures the VS Code editor.

Type Checking: python.analysis.typeCheckingMode: Enables Python's type checker.
Linting: python.linting.ruffEnabled: Enables ruff as the linter.
Formatting: python.formatting.provider: Disables default formatter, since pre-commit is being used.
Ruff Settings: Settings for Ruff language server (e.g., importStrategy, organizeImports, fixAll, showSyntaxErrors).
ruff.configurationPreference: prioritize file based configs.

Here are some additional configurations that are often useful and are commonly used or at least helpful if applicable.

constraint-dependencies: If you want to pin a transitive dependency to a specific version use constraint-dependencies.

    [tool.uv]
        constraint-dependencies = ["cryptography<42.0.0"]
    

override-dependencies: Forces a dependency to use a specific version

    [tool.uv]
        override-dependencies = ["cryptography==42.0.0"]
    

index: You can specify additional package indexes to get dependencies from

    [[tool.uv.index]]
     name = "pytorch"
     url = "https://download.pytorch.org/whl/cu121"
     explicit = true

[tool.uv.sources]
torch = { index = "pytorch" }

pytest.ini: Create a pytest.ini in your root folder to configure options for pytest.

    [pytest]
    testpaths = tests
    addopts =
        --cov=src/my_package
        --cov-report term-missing
        -vv
    

This will make sure that pytest runs against all tests in the tests folder

It will also add coverage info for src/my_package

It will also run in verbose mode

You can add additional hooks from other repositories.

You can configure existing hooks as needed. For example if you want to exclude files from ruff you can use:

-   id: ruff
    args: ["--fix", "--exclude", "path/to/exclude"]

- Create one venv per project to avoid dependency conflicts
- Don't commit the .venv directory (it's in .gitignore)
- On Windows, if UV fails, fall back to python -m venv
- Rebuild venv if you suspect dependency issues

select

List of rules enabled from `ruff` and different linters.

ignore

List of rules ignored.

per-file-ignores

Configure specific files or patterns for ignoring certain rules.

default-groups = ["dev"]: Sets dev dependencies to be installed by default.

line-length = 100: Sets the maximum line length.
select: List of rules enabled from ruff and different linters.
ignore: List of rules ignored.
fix = true: Automatically fix linting errors.
per-file-ignores: Configure specific files or patterns for ignoring certain rules.
quote-style = "single": Sets style to use single quotes.

mypy_path = "src": The location of your packages for mypy type checking.
python_version = "3.10": The Python version being used.
strict = true: Enables strict type checking options.

  • plugins = ["pytest_mypy_plugins"]: Makes pytest plugin available for mypy.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "python best practices launchpad": {
            "FastMCP-Proper": {
                "command": "uv",
                "args": [
                    "venv"
                ]
            }
        }
    }
}

McpServers

{
    "FastMCP-Proper": {
        "command": "uv",
        "args": [
            "venv"
        ]
    }
}

CI
Python 3.10+
Code style: ruff
License: MIT

This repository provides a modern Python project template with a functional FastAPI REST API, designed for efficient development with uv, ruff, mypy, pytest, and Git hooks powered by pre-commit. It demonstrates best practices for building production-ready Python applications with robust testing, containerization, and CI/CD integration.

Features

REST API with FastAPI: Ready-to-use API with data validation using Pydantic models.
Docker & Docker Compose: Production-ready containerization with multi-stage builds.
uv for Dependency Management: Fast and efficient dependency resolution and virtual environment management.
ruff for Linting and Formatting: Enforces consistent code style, catches errors early, and provides auto-fixing capabilities.
mypy for Type Checking: Adds static typing to your Python code, preventing type-related errors.
pytest for Testing: Comprehensive test suite with unit, API, and integration tests.
pre-commit for Git Hooks: Automates code quality checks before every commit.
GitHub Actions Workflow: Ready-to-use CI pipeline for testing and quality assurance.
Dev Container Support: Included configuration for instant development in VS Code or GitHub Codespaces.

Project Structure

2024-Python-Best-Practices-Launchpad/
├── .github/workflows/       # GitHub workflows for CI/CD
│   └── main.yml             # Main CI workflow
├── .devcontainer/           # Dev Container configuration
│   ├── devcontainer.json    # Dev container settings
│   └── Dockerfile           # Dev container image definition
├── src/                     # Source code directory
│   └── my_package/          # Main package directory
│       ├── __init__.py      # Package initialization
│       ├── api.py           # FastAPI implementation
│       ├── models.py        # Pydantic data models
│       ├── module.py        # Core functionality
│       ├── example.py       # Example calculator class
│       └── run.py           # Script to run the FastAPI server
├── tests/                   # Test directory
│   ├── test_api.py          # Tests for FastAPI endpoints using models
│   ├── test_endpoints.py    # Tests for API endpoints using test client
│   ├── test_module.py       # Tests for core functionality
│   ├── test_example.py      # Tests for example calculator
│   └── integration_test.py  # Integration tests
├── .pre-commit-config.yaml  # Pre-commit hooks configuration
├── docker-compose.yml       # Docker Compose configuration
├── Dockerfile               # Multi-stage production Docker image
├── LICENSE                  # MIT License
├── pyproject.toml           # Project configuration and dependencies
├── pytest.ini               # Pytest configuration
└── README.md                # This file

API Features

The included FastAPI application provides:

Data processing API with input validation
Proper error handling and status codes
CORS middleware for cross-origin requests
Automatic OpenAPI documentation (available at /docs)
Pydantic models for request/response schema validation

Getting Started

You can choose one of two approaches to set up this project:

Option 1: Using Dev Containers (Recommended)

If you have VS Code with the Dev Containers extension or GitHub Codespaces, you can get started quickly without any local setup:

1. VS Code + Dev Containers:
- Clone this repository
- Open the repository folder in VS Code
- When prompted "Reopen in Container", click "Reopen in Container"
- (Alternatively, press F1, type "Reopen in Container" and select the option)

2. GitHub Codespaces:
- Click the "Code" button on the GitHub repository
- Select the "Codespaces" tab
- Click "Create codespace on main"

The container includes all necessary tools and dependencies, properly configured and ready to use.

Option 2: Using Docker Compose

To run the API using Docker Compose:

```bash

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.