Python wrapper for the Copperlace text renderer
Project description
Copperlace Python
Python wrapper for the Copperlace renderer.
The wheel build runs Cargo for ../rust-core, bundles the resulting native
library, and exposes a small Python API over the Copperlace C ABI.
from copperlace import Copperlace
with Copperlace.from_string('name = ["Mia"]\norigin = "{name}"') as copperlace:
print(copperlace.render("origin"))
print(copperlace.render("origin"))
print(copperlace.render("origin", {"name": "Darcy"}))
with Copperlace.from_string(
'name = ["Mia"]\norigin = "{name | shout}"',
{"shout": lambda value: value.upper()},
) as copperlace:
print(copperlace.render("origin"))
Structured rendering returns JSON strings for object-valued rules:
from copperlace import render_str_structured
config = """
name = ["Mia"]
origin {
title = "Hello {name}"
tags = ["structured", "{name | slug}"]
count = 3
active = true
missing = null
}
"""
print(render_str_structured(config, "origin"))
# {
# "active": true,
# "count": 3,
# "missing": null,
# "tags": [
# "structured",
# "mia"
# ],
# "title": "Hello Mia"
# }
RuleSet.render_structured, Copperlace.render_structured,
render_str_structured, and render_file_structured return formatted JSON
strings from the native renderer.
Use inferred rendering when callers want the CLI-style behavior from one method: text rules return text, list rules keep random text choice behavior, and object-valued rules return a formatted JSON string.
from copperlace import render_str_inferred
print(render_str_inferred(config, "origin"))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file copperlace-0.2.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.
File metadata
- Download URL: copperlace-0.2.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e594f05857fd6b6d02e4a6e22f49451d71e92fe5ae2c548d0ae58e323a4f44a
|
|
| MD5 |
81f0027a8eb6010bf5fa58ded7536ae5
|
|
| BLAKE2b-256 |
59458d863b07e35b7b278b4bc38d2736359bb572d83bda081c2a2caee6b46b5e
|