Principle:Langchain ai Langchain Package Configuration
Overview
A standard approach for configuring a Python package using pyproject.toml, including build system, dependencies, development groups, and tool settings.
Description
The Package Configuration principle describes how LangChain partner integration packages declare their build system, runtime dependencies, development dependency groups, and tool configurations through a single pyproject.toml file. This file is the central configuration point for each package in the monorepo.
Key configuration sections include:
[build-system]: Specifies the build backend. LangChain packages usehatchlingas the build backend, which provides fast, standards-compliant Python package building.[project]: Declares the package name, version, description, license, Python version constraints, classifiers, and runtime dependencies. The critical runtime dependency islangchain-core, which provides base abstractions.[project.urls]: Links to documentation, repository, issues, changelog, and community channels.[dependency-groups]: Defines separate dependency groups for different development activities:test: Testing dependencies (pytest, pytest-asyncio, pytest-socket, langchain-tests)test_integration: Additional dependencies needed only for integration testslint: Linting tools (ruff)typing: Type-checking tools (mypy)dev: General development dependencies
[tool.uv.sources]: Maps internal LangChain packages to local editable installs for development, ensuring that changes tolangchain-coreorlangchain-testsare immediately reflected.- Tool configurations: Settings for mypy, ruff (linting and formatting), pytest, and coverage.
Usage
Apply this principle when:
- Creating a new
pyproject.tomlfor a partner integration package. - Adding or updating dependencies for an existing package.
- Configuring development tools (linter, formatter, type checker) for a package.
- Understanding how the monorepo's dependency resolution works across packages.
Theoretical Basis
Modern Python packaging relies on pyproject.toml as defined by PEP 517, PEP 518, and PEP 621. The dependency-groups pattern separates concerns so that CI can install only the tools needed for a specific job (e.g., uv sync --group test for testing, uv sync --group lint for linting).
[build-system]
requires = ["<build-backend>"]
build-backend = "<build-backend>.build"
[project]
name = "langchain-<integration>"
version = "<semver>"
dependencies = [
"langchain-core>=<min>,<max>",
# ... other runtime deps
]
[dependency-groups]
test = ["pytest", "langchain-tests", ...]
lint = ["ruff"]
typing = ["mypy"]
[tool.uv.sources]
langchain-core = { path = "../../core", editable = true }
langchain-tests = { path = "../../standard-tests", editable = true }