Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

copperlace-0.2.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (1.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

File details

Details for the file copperlace-0.2.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for copperlace-0.2.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 2e594f05857fd6b6d02e4a6e22f49451d71e92fe5ae2c548d0ae58e323a4f44a
MD5 81f0027a8eb6010bf5fa58ded7536ae5
BLAKE2b-256 59458d863b07e35b7b278b4bc38d2736359bb572d83bda081c2a2caee6b46b5e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page