A library for rendering project templates from Git repositories with Jinja2 templating and interactive questionnaires.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
The primary functions for template processing in Copier. These functions provide the essential operations for project generation and maintenance workflows.
Generate a new project from a template source (local path or Git repository).
def run_copy(
src_path: str,
dst_path: StrOrPath = ".",
data: AnyByStrDict | None = None,
**kwargs: Any
) -> Worker:
"""
Copy a template to a destination from zero.
Parameters:
- src_path (str): Template source path (local or Git URL)
- dst_path (StrOrPath): Destination path for the new project
- data (dict, optional): Answers to template questions
- **kwargs: Additional configuration options
Returns:
Worker: Configured worker instance after generation
"""Usage examples:
from copier import run_copy
# Generate from Git repository
worker = run_copy(
src_path="https://github.com/copier-org/copier.git",
dst_path="./my-project",
data={"project_name": "MyApp", "author": "Jane Doe"}
)
# Generate from local template
worker = run_copy(
src_path="./my-template",
dst_path="./new-project",
data={"version": "1.0.0"}
)
# Use specific Git ref
worker = run_copy(
src_path="https://github.com/user/template.git",
dst_path="./project",
vcs_ref="v2.0.0",
data={"feature_enabled": True}
)Update an existing project when the template evolves, preserving local changes and applying template updates.
def run_update(
dst_path: StrOrPath = ".",
data: AnyByStrDict | None = None,
**kwargs: Any
) -> Worker:
"""
Update a subproject from its template with evolution.
Parameters:
- dst_path (StrOrPath): Path to existing project to update
- data (dict, optional): New or updated answers
- **kwargs: Additional configuration options
Returns:
Worker: Configured worker instance after update
"""Usage examples:
from copier import run_update
# Update current directory project
worker = run_update()
# Update specific project with new data
worker = run_update(
dst_path="./my-project",
data={"new_feature": True, "version": "2.0.0"}
)
# Update to specific template version
worker = run_update(
dst_path="./my-project",
vcs_ref="v3.0.0"
)Regenerate a project from its template, discarding evolution but keeping user answers.
def run_recopy(
dst_path: StrOrPath = ".",
data: AnyByStrDict | None = None,
**kwargs: Any
) -> Worker:
"""
Update a subproject from its template, discarding evolution.
Parameters:
- dst_path (StrOrPath): Path to existing project to regenerate
- data (dict, optional): Updated answers for regeneration
- **kwargs: Additional configuration options
Returns:
Worker: Configured worker instance after regeneration
"""Usage examples:
from copier import run_recopy
# Regenerate current directory project
worker = run_recopy()
# Regenerate with updated answers
worker = run_recopy(
dst_path="./my-project",
data={"template_version": "latest", "cleanup": True}
)All core operations accept these common keyword arguments:
vcs_ref (str): Git tag, branch, or commit to useanswers_file (str): Path to answers file (default: ".copier-answers.yml")exclude (list): File patterns to exclude from processingskip_if_exists (list): File patterns to skip if they existoverwrite (bool): Whether to overwrite existing filesdefaults (bool): Use default answers without promptingpretend (bool): Perform dry run without actual changesquiet (bool): Suppress output during processingcleanup_on_error (bool): Delete destination on errorunsafe (bool): Allow potentially unsafe template featuresAll core operations return a Worker instance that can be used for:
# Using returned worker
worker = run_copy("template/", "project/")
print(f"Template used: {worker.template}")
print(f"Answers: {worker.data}")
# Context manager usage
with run_copy("template/", "project/") as worker:
# Additional processing
passInstall with Tessl CLI
npx tessl i tessl/pypi-copier