Skip to main content

A python template engine

Project description

PyForma

A Python template engine featuring partial substitution.

Tests

Example

from pyforma import Template

template = Template("Hello, {{ subject }}! This is {{ lib_name }}.")
assert template.unresolved_identifiers() == {"subject", "lib_name"}

template = template.substitute({"lib_name": "PyForma"})
assert template.unresolved_identifiers() == {"subject"}

print(template.render({"subject": "World"}))  # Prints "Hello, World! This is PyForma."

Features

  • 100% Python
  • Python-like expressions in templates
  • Special-purpose environments for more expressive templates
  • Templates can be inspected for what variables need to be substituted
  • Can partially substitute variables within templates
  • Rendering with undefined variables results in an error
  • Fully statically typed

Documentation

Alternatives

  • Jinja2: The de-facto standard Python template engine. It's popular, fast, expressive and extensible, but doesn't support partial template substitution.
  • Mako: Compiles templates to Python bytecode.
  • Chameleon: HTML/XML-compatible template engine.
  • string.Template: The actual standard Python template engine. Pretty limited functionality.

Project details


Download files

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

Source Distribution

pyforma-0.6.0.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

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

pyforma-0.6.0-py3-none-any.whl (39.6 kB view details)

Uploaded Python 3

File details

Details for the file pyforma-0.6.0.tar.gz.

File metadata

  • Download URL: pyforma-0.6.0.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for pyforma-0.6.0.tar.gz
Algorithm Hash digest
SHA256 2ca739d1cf3127222f3041ed7ac8bf2041d3f3022f0af28f6f2d800ae39934e4
MD5 91c7fac36d753360ad1c510330bfc435
BLAKE2b-256 4b0e2b8f942ce6db4fc538ff5e5f5c553d37ee9acfa8c347cc9f3500c6107b9e

See more details on using hashes here.

File details

Details for the file pyforma-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: pyforma-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 39.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for pyforma-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3bb69d67513c36549943248c45505bcec893deeda9cdc1b10a3604a25baf6b76
MD5 67a9d09525aba1dcc315679fcffdadc3
BLAKE2b-256 6dbe1ecbbe1f889a56e5af0a469ee758dc164e197f0c232ce2a8e88ef8c89a7e

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