TOML 06 ๐ Configuration Patterns for Cargo, Pyproject, and Hugo
TOML’s adoption is not abstract. Three tools define the patterns that most developers encounter: Cargo (Rust), pyproject.toml (Python packaging), and Hugo (static sites). Each uses the same TOML syntax but organizes it differently, and each has conventions that determine which tables are required, which are optional, and which are tool-specific escape hatches. Understanding these three patterns covers the majority of TOML files in existence.
This chapter covers the structural conventions of the three dominant TOML configurations: the Cargo.toml manifest with its package metadata, dependency tables, and workspace inheritance; the pyproject.toml specification with its [project] table, optional dependencies, and tool-specific sections; and Hugo’s config.toml with its site-wide settings, parameters, and environment variable overrides. The sections that follow walk through each tool’s pattern and the composition rules that determine how the tables fit together.
Key point: Cargo requires only [package] name but publishing requires more; pyproject.toml requires [project] name and uses [build-system] for the backend; Hugo uses top-level keys for site settings and [params] for template-accessible data.
a. Cargo.toml: the Rust manifest
Cargo.toml is the package manifest that Cargo reads to build a Rust crate. The only strictly required field is package.name; a crate with no targets fails to build, but the manifest itself parses with just a name . Publishing to crates.io requires additional metadata: version, description, and either license or license-file .
[package]
name = "api-client" # required
version = "0.3.0" # required for publishing
edition = "2024" # defaults to 2015 if absent
rust-version = "1.85" # MSRV, resolver input
license = "MIT OR Apache-2.0" # SPDX expression
description = "Client library for an internal JSON API."
[dependencies]
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
[dev-dependencies]
pretty_assertions = "1.4.1"
[lints.rust]
unsafe_code = "forbid"
Dependencies use three table forms: [dependencies] for runtime, [dev-dependencies] for tests and examples, and [build-dependencies] for build scripts . An inline table { version, features } is the compact form; a full [dependencies.serde] table is the expanded form. The [features] table defines conditional compilation flags, and [profile.*] customizes optimization and debug settings.
For workspaces, [workspace] at the root defines members, and member crates inherit metadata with .workspace = true. Settings like [patch] and [profile.*] are ignored in member manifests and must be at the workspace root . Tool-specific data belongs under [package.metadata], which Cargo ignores entirelyโthis is how tools like cargo-ndk store Android configuration without triggering unused-key warnings .
b. pyproject.toml: the Python packaging standard
pyproject.toml is the standardized configuration file for Python packaging. The [project] table holds metadata following PEP 621; name is the only statically required field, and version is required but may be dynamic . The [build-system] table declares the backend that builds the package.
[project]
name = "spam-eggs"
version = "2020.0.0"
description = "Lovely Spam! Wonderful Spam!"
readme = "README.md"
requires-python = ">= 3.8"
dependencies = [
"httpx",
"gidgethub[httpx]>4.0.0",
]
[project.optional-dependencies]
cli = ["rich", "click"]
gui = ["PyQt5"]
[project.scripts]
spam-cli = "spam:main_cli"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
dependencies is an array of PEP 508 dependency specifiers. [project.optional-dependencies] defines extrasโnamed groups installed with pip install package[extra] . The [project.scripts] table creates console entry points; [project.gui-scripts] is the Windows variant that suppresses the terminal window .
The [tool.*] namespace is where tool-specific configuration lives. Ruff, pytest, mypy, and coverage all read their settings from [tool.ruff], [tool.pytest.ini_options], and similar tables. The [dependency-groups] table is a newer convention for development dependencies, distinct from optional runtime extras .
c. Hugo: the static site configuration
Hugo looks for config.toml, config.yaml, or config.json in the site root, in that order. Top-level keys set site-wide values: baseURL, title, languageCode, theme . The [params] table holds custom values accessible in templates as .Site.Params.
baseURL = "https://example.com/"
title = "My Hugo Site"
languageCode = "en-us"
theme = "ananke"
[params]
subtitle = "Hugo is absurdly fast"
authorName = "Jon Doe"
sidebarRecentLimit = 5
[permalinks]
posts = "/:year/:month/:title/"
[menus]
[[menus.main]]
name = "Home"
url = "/"
weight = 1
Hugo allows configuration to be split across files in a config/ directory, organized by environment and root key. config/_default/hugo.toml holds defaults, and config/production/params.toml overrides them in production . Environment variables prefixed with HUGO_ override any setting; HUGO_PARAMS_SUBTITLE sets params.subtitle . For snake_case keys, the delimiter after HUGO determines how the name is parsedโHUGOxPARAMSxAPI_KEY uses x as the separator .
The [frontmatter] table controls how dates are extracted from content files, and [markup] configures syntax highlighting and rendering. The [[menus.main]] array-of-tables form defines menu entries, with name, url, and weight as the common keys.
Complete Example Session
# ============================================
# PART 1: CARGO.TOML PATTERN
# ============================================
[package]
name = "my-crate"
version = "0.1.0"
edition = "2024"
rust-version = "1.85"
license = "MIT"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
[dev-dependencies]
criterion = "0.5"
[features]
default = []
extra = ["serde"]
[package.metadata.docs.rs]
all-features = true
# ============================================
# PART 2: PYPROJECT.TOML PATTERN
# ============================================
[project]
name = "my-package"
version = "1.0.0"
requires-python = ">=3.10"
dependencies = ["requests>=2.0"]
[project.optional-dependencies]
dev = ["pytest", "ruff"]
[project.scripts]
my-cli = "my_package.cli:main"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.ruff]
line-length = 100
# ============================================
# PART 3: HUGO CONFIG.TOML PATTERN
# ============================================
baseURL = "https://example.com/"
title = "My Site"
theme = "ananke"
[params]
description = "A Hugo site"
githubUser = "example"
[permalinks]
posts = "/:year/:month/:title/"
[[menus.main]]
name = "About"
url = "/about/"
weight = 10
# ============================================
# PART 4: THE STRUCTURAL PATTERN
# ============================================
# Cargo: [package] + [dependencies] + tool metadata
# Pyproject: [project] + [build-system] + [tool.*]
# Hugo: top-level keys + [params] + array tables
The parts covered the Cargo manifest pattern, the pyproject project and build-system pattern, the Hugo site configuration pattern, and the structural commonalities across all three.
Quick Reference
Cargo.toml Tables
| Table | Purpose | Required |
|---|---|---|
[package] | Identity, version, edition | name only |
[dependencies] | Runtime crates | No |
[dev-dependencies] | Test/example crates | No |
[features] | Conditional compilation | No |
[package.metadata] | Tool-specific data | No |
pyproject.toml Tables
| Table | Purpose | Required |
|---|---|---|
[project] | Metadata, dependencies | name only |
[build-system] | Build backend | Recommended |
[project.optional-dependencies] | Extras | No |
[project.scripts] | Entry points | No |
[tool.*] | Tool configuration | No |
Hugo Configuration
| Key/Table | Purpose |
|---|---|
baseURL, title, theme | Site-wide settings |
[params] | Template-accessible custom data |
[permalinks] | URL patterns |
[[menus.main]] | Menu entries |
[frontmatter] | Date extraction rules |
Best Practices
โ Do This:
# Cargo: set edition explicitly
edition = "2024" # โ
# pyproject: pin requires-python
requires-python = ">=3.10" # โ
# Hugo: put custom values under [params]
[params]
authorName = "Jon Doe" # โ
# Use inline tables for compact dependencies
serde = { version = "1.0", features = ["derive"] } # โ
โ Don’t Do This:
# Cargo: rely on edition default
# (defaults to 2015, not current) # โ
# pyproject: omit build-system for new projects
# (backend cannot be resolved) # โ
# Hugo: put template data at top level
authorName = "Jon Doe" # not in [params], not accessible # โ
# pyproject: use [project.dependencies] as a table
# (it is an array of strings) # โ
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| Cargo build fails with no targets | Manifest has only [package] | Add src/lib.rs or src/main.rs |
| pyproject backend not found | No [build-system] table | Add backend declaration |
| Hugo params not in templates | Values at top level | Move under [params] |
| Cargo unused key warning | Typo or tool data at top level | Use [package.metadata] |
Real-World Examples
1. Cargo package identity
[package]
name = "my-crate"
version = "0.1.0"
2. Cargo dependency with features
serde = { version = "1.0", features = ["derive"] }
3. Cargo tool metadata
[package.metadata.docs.rs]
all-features = true
4. pyproject project metadata
[project]
name = "my-package"
version = "1.0.0"
5. pyproject optional dependencies
[project.optional-dependencies]
dev = ["pytest"]
6. pyproject entry point
[project.scripts]
my-cli = "my_package:main"
7. Hugo site settings
baseURL = "https://example.com/"
title = "My Site"
8. Hugo params
[params]
author = "Name"
9. Hugo menu
[[menus.main]]
name = "Home"
url = "/"
10. Hugo permalinks
[permalinks]
posts = "/:year/:title/"
Visual
Three Configuration Patterns
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CARGO.TOML โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ [package] identity, version โ โ
โ โ [dependencies] runtime crates โ โ
โ โ [dev-dependencies] test crates โ โ
โ โ [features] compile flags โ โ
โ โ [package.metadata] tool escape hatch โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ PYPROJECT.TOML โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ [project] metadata, deps โ โ
โ โ [build-system] backend โ โ
โ โ [project.optional-dependencies] extras โ โ
โ โ [project.scripts] entry points โ โ
โ โ [tool.*] tool config โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ HUGO CONFIG.TOML โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ top-level keys baseURL, title, theme โ โ
โ โ [params] template data โ โ
โ โ [permalinks] URL patterns โ โ
โ โ [[menus.main]] menu entries โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The Tool Namespace Pattern
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ WHERE TOOL CONFIG GOES โ
โ โ
โ Cargo: [package.metadata.*] โ
โ Cargo ignores, tools read โ
โ โ
โ pyproject: [tool.*] โ
โ Standard namespace for external tools โ
โ โ
โ Hugo: [params] โ
โ Templates read via .Site.Params โ
โ โ
โ All three: the tool owns its namespace โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Required vs Optional
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ REQUIRED FIELDS โ
โ โ
โ Cargo: [package] name โ
โ pyproject: [project] name โ
โ Hugo: none (but baseURL/title are practical) โ
โ โ
โ PUBLISHING REQUIREMENTS โ
โ โ
โ Cargo: version, description, license โ
โ pyproject: version (unless dynamic) โ
โ Hugo: N/A โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary
| Tool | File | Required | Tool Namespace |
|---|---|---|---|
| Cargo | Cargo.toml | [package] name | [package.metadata] |
| Python | pyproject.toml | [project] name | [tool.*] |
| Hugo | config.toml | None (practical: baseURL) | [params] |
Key takeaways:
- Cargo’s manifest is minimal at parse time and demanding at publish time.
[package] nameis the only strictly required field, but publishing requiresversion,description, and a license. The[package.metadata]table is the escape hatch for tool-specific data that Cargo ignores . - pyproject.toml separates metadata from build configuration.
[project]holds PEP 621 metadata and[build-system]declares the backend. The[tool.*]namespace is where every Python tool (Ruff, pytest, mypy) stores its settings . - Hugo uses top-level keys for site settings and
[params]for template data. Values at the top level are not accessible as.Site.Params; custom data belongs under[params]. Environment variables prefixed withHUGO_override any setting . - The tool namespace pattern is consistent. Each ecosystem provides a designated table for external tools to store configuration without triggering unused-key warnings or polluting the standard namespace.
- The required fields are few. All three tools parse with minimal configuration; the additional tables are for functionality, not for a valid file.
Remember: TOML’s value in these three tools is the same as in any configuration: explicit structure, no implicit typing, and a place for everything. Cargo’s [package] and [dependencies], pyproject’s [project] and [build-system], Hugo’s top-level keys and [params]โeach is a convention built on the same syntax. When writing a TOML file for one of these tools, the question is not “is this valid TOML?” but “is this the table the tool expects?” The answer is in the tool’s documentation, not the TOML specification.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!