Registry / devops / craft-parts

craft-parts

JSON →
library2.34.0pypypi✓ verified 85d ago

Craft Parts is a Python package that provides a reusable and extensible framework for defining, processing, and organizing software components into deployment-ready filesystems. It supports various source types and build plugins, enabling declarative management of complex build processes and dependencies. The library is actively developed by Canonical and is a core component for tools like Snapcraft and Charmcraft, with regular releases.

pip install craft-parts
INSTALL
IMPORT
SIG · CRAFT-PARTS
C
craft-parts
devopspythonv2.34.0
Install
4.7s avg
Import
Disk
60MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.34.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 63.7MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 4.7s · import 0.000s · 72MB
60MB installed
● package 60MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LifecycleManager
from craft_parts import LifecycleManager
from craft_parts.lifecycle import LifecycleManager

This quickstart demonstrates programmatically defining a simple 'hello' part that uses the 'dump' plugin to copy a source file. It then initializes a `LifecycleManager` to plan and execute the full crafting process (pull, build, stage, prime) within a temporary project structure, printing the output file.

import os import pathlib from craft_parts.models import PartSpec, Part from craft_parts.lifecycle import LifecycleManager, Step # Create a dummy project directory project_dir = pathlib.Path('./my-craft-project') project_dir.mkdir(exist_ok=True) # Create a simple parts.yaml content parts_yaml_content = ''' parts: hello: plugin: dump source: hello.txt ''' (project_dir / 'parts.yaml').write_text(parts_yaml_content) (project_dir / 'hello.txt').write_text('Hello from Craft Parts!') # Define the part specification programmatically part_spec = PartSpec( name="hello", part=Part( plugin="dump", source="hello.txt" ) ) # Initialize LifecycleManager lcm = LifecycleManager( parts={part_spec.name: part_spec.part}, application_name="my-craft-app", project_dir=project_dir, build_dir=project_dir / 'build', stage_dir=project_dir / 'stage', prime_dir=project_dir / 'prime', cache_dir=project_dir / '.cache' ) # Plan and execute the full lifecycle actions = lcm.plan(Step.PRIME) with lcm.action_executor() as aex: aex.execute(actions) print(f"Project built to: {project_dir / 'prime'}") print(f"Content of staged file: {(project_dir / 'prime' / 'hello.txt').read_text()}")
Debug
Known issues
gotchaUnderstanding the part lifecycle (pull, overlay, build, stage, prime) is crucial. Misconfiguring `source`, `build-packages`, `stage-packages`, or `prime` properties can lead to unexpected build outputs or missing files in the final artifact.
fix
Thoroughly review the 'Parts lifecycle' and 'Part properties' sections in the official documentation. Use `craft_parts --dry-run` to inspect the planned steps before a full build.
affects: All versions
gotchaWhen developing custom plugins or overriding build steps, ensure correct environment variable propagation and command execution within the isolated build environments. Pathing issues are common.
fix
Refer to the 'Create a plugin' and 'Override a part's default build behavior' guides. Use verbose logging and inspect environment setup scripts if commands fail to execute as expected. Test custom scripts incrementally.
affects: All versions
gotchaThe `dump` plugin simply copies source files. If your part requires compilation or complex build steps, you must specify an appropriate plugin (e.g., `autotools`, `cmake`, `poetry`, `go`) or provide `override-build` instructions.
fix
Always select a plugin that matches your project's build system. If no suitable plugin exists, use `plugin: nil` and define `override-pull`, `override-build`, `override-stage`, etc., as needed in your `parts.yaml` or `Part` definition.
affects: All versions
Upgrade
Version history
2.34.0latest on PyPI · released Jun 11, 2026
Audit
Dependencies
craft-clirequiredCommand-line client builder framework.
craft-applicationrequiredApplication-level crafting utilities.
craft-providersrequiredManages software builds in containers.
craft-archivesrequiredManages interaction with software package repositories.
craft-grammarrequiredProvides Python interfaces for advanced grammar.
craft-platformsrequiredPlatform-specific utilities for crafting.
craft-storerequiredStorage utilities for crafting artifacts.
distrorequiredDetermines Linux distribution information.
pydanticrequiredData validation and settings management using Python type hints.
pyyamlrequiredYAML parser and emitter for Python.
requestsrequiredHTTP library for making web requests.
requests-toolbeltrequiredUtility belt for the Requests library.
simplejsonrequiredSimple, fast, extensible JSON encoder/decoder.
typing-extensionsrequiredBackports and experimental type hints.
validatorsrequiredValidation for various types of data.
attrsrequiredClasses without boilerplate.
jsonschemarequiredJSON Schema validation.
setuptoolsrequiredRequired for package metadata and setup utilities.
Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
craft-parts — pip install craft-parts · libregistry