🎯

python-skills

🎯Skill

from llama-farm/llamafarm

VibeIndex|
What it does

Provides comprehensive Python best practices and code review guidelines for ensuring high-quality, secure, and maintainable code across LlamaFarm's Python components.

python-skills

Installation

Install skill:
npx skills add https://github.com/llama-farm/llamafarm --skill python-skills
8
Last UpdatedJan 26, 2026

Skill Details

SKILL.md

Shared Python best practices for LlamaFarm. Covers patterns, async, typing, testing, error handling, and security.

Overview

# Python Skills for LlamaFarm

Shared Python best practices and code review checklists for all Python components in the LlamaFarm monorepo.

Applicable Components

| Component | Path | Python | Key Dependencies |

|-----------|------|--------|-----------------|

| Server | server/ | 3.12+ | FastAPI, Celery, Pydantic, structlog |

| RAG | rag/ | 3.11+ | LlamaIndex, ChromaDB, Celery |

| Universal Runtime | runtimes/universal/ | 3.11+ | PyTorch, transformers, FastAPI |

| Config | config/ | 3.11+ | Pydantic, JSONSchema |

| Common | common/ | 3.10+ | HuggingFace Hub |

Quick Reference

| Topic | File | Key Points |

|-------|------|------------|

| Patterns | [patterns.md](patterns.md) | Dataclasses, Pydantic, comprehensions, imports |

| Async | [async.md](async.md) | async/await, asyncio, concurrent execution |

| Typing | [typing.md](typing.md) | Type hints, generics, protocols, Pydantic |

| Testing | [testing.md](testing.md) | Pytest fixtures, mocking, async tests |

| Errors | [error-handling.md](error-handling.md) | Custom exceptions, logging, context managers |

| Security | [security.md](security.md) | Path traversal, injection, secrets, deserialization |

Code Style

LlamaFarm uses ruff with shared configuration in ruff.toml:

```toml

line-length = 88

target-version = "py311"

select = ["E", "F", "I", "B", "UP", "SIM"]

```

Key rules:

  • E, F: Core pyflakes and pycodestyle
  • I: Import sorting (isort)
  • B: Bugbear (common pitfalls)
  • UP: Upgrade syntax to modern Python
  • SIM: Simplify code patterns

Architecture Patterns

Settings with pydantic-settings

```python

from pydantic_settings import BaseSettings

class Settings(BaseSettings, env_file=".env"):

LOG_LEVEL: str = "INFO"

HOST: str = "0.0.0.0"

PORT: int = 8000

settings = Settings() # Singleton at module level

```

Structured Logging with structlog

```python

from core.logging import FastAPIStructLogger # Server

from core.logging import RAGStructLogger # RAG

from core.logging import UniversalRuntimeLogger # Runtime

logger = FastAPIStructLogger(__name__)

logger.info("Operation completed", extra={"count": 10, "duration_ms": 150})

```

Abstract Base Classes for Extensibility

```python

from abc import ABC, abstractmethod

class Component(ABC):

def __init__(self, name: str, config: dict[str, Any] | None = None):

self.name = name or self.__class__.__name__

self.config = config or {}

@abstractmethod

def process(self, documents: list[Document]) -> ProcessingResult:

pass

```

Dataclasses for Internal Data

```python

from dataclasses import dataclass, field

@dataclass

class Document:

content: str

metadata: dict[str, Any] = field(default_factory=dict)

id: str = field(default_factory=lambda: str(uuid.uuid4()))

```

Pydantic Models for API Boundaries

```python

from pydantic import BaseModel, Field, ConfigDict

class EmbeddingRequest(BaseModel):

model: str

input: str | list[str]

encoding_format: Literal["float", "base64"] | None = "float"

model_config = ConfigDict(str_strip_whitespace=True)

```

Directory Structure

Each Python component follows this structure:

```

component/

β”œβ”€β”€ pyproject.toml # UV-managed dependencies

β”œβ”€β”€ core/ # Core functionality

β”‚ β”œβ”€β”€ __init__.py

β”‚ β”œβ”€β”€ settings.py # Pydantic Settings

β”‚ └── logging.py # structlog setup

β”œβ”€β”€ services/ # Business logic (server)

β”œβ”€β”€ models/ # ML models (runtime)

β”œβ”€β”€ tasks/ # Celery tasks (rag)

β”œβ”€β”€ utils/ # Utility functions

└── tests/

β”œβ”€β”€ conftest.py # Shared fixtures

└── test_*.py

```

Review Checklist Summary

When reviewing Python code in LlamaFarm:

  1. Patterns (Medium priority)

- Modern Python syntax (3.10+ type hints)

- Dataclass vs Pydantic used appropriately

- No mutable default arguments

  1. Async (High priority)

- No blocking calls in async functions

- Proper asyncio.Lock usage

- Cancellation handled correctly

  1. Typing (Medium priority)

- Complete return type hints

- Generic types parameterized

- Pydantic v2 patterns

  1. Testing (Medium priority)

- Fixtures properly scoped

- Async tests use pytest-asyncio

- Mocks cleaned up

  1. Errors (High priority)

- Custom exceptions with context

- Structured logging with extra dict

- Proper exception chaining

  1. Security (Critical priority)

- Path traversal prevention

- Input sanitization

- Safe deserialization

See individual topic files for detailed checklists with grep patterns.

More from this repository10

🎯
common-skills🎯Skill

Manages shared Python utilities for LlamaFarm, focusing on HuggingFace model handling, GGUF file management, and cross-service consistency.

🎯
rag-skills🎯Skill

Implements robust RAG document processing and retrieval using LlamaIndex, ChromaDB, and Celery for efficient, scalable AI document workflows.

🎯
generate-subsystem-skills🎯Skill

Generates specialized Claude Code skills for each subsystem, creating shared language and subsystem-specific checklists to optimize AI code generation across the monorepo.

🎯
electron-skills🎯Skill

Configures secure Electron desktop application architecture with isolated processes, type-safe IPC, and cross-platform packaging for LlamaFarm.

🎯
go-skills🎯Skill

Enforces Go best practices and idiomatic patterns for secure, maintainable LlamaFarm CLI development.

🎯
typescript-skills🎯Skill

Enforces strict TypeScript best practices for React and Electron frontend applications, ensuring type safety, immutability, and clean code patterns.

🎯
cli-skills🎯Skill

Provides comprehensive Go CLI development guidelines using Cobra, Bubbletea, and Lipgloss for creating robust, interactive command-line interfaces in LlamaFarm projects.

🎯
commit-push-pr🎯Skill

Automates git workflow by committing changes, pushing to GitHub, and opening a PR with intelligent checks and handling of edge cases.

🎯
server-skills🎯Skill

Provides server-side best practices and code review guidelines for FastAPI, Celery, and Pydantic frameworks in Python.

🎯
runtime-skills🎯Skill

Optimizes ML inference runtime with best practices for PyTorch, Transformers, and FastAPI, focusing on device management, model loading, and performance tuning.