Skip to main content

A Python templating engine inspired by ReactJS functional components

Project description

Purepy

Purepy is a Python templating engine inspired by ReactJS functional components.

Why use Purepy?

To enjoy pure Python programming.

In traditional approaches, mixing HTML code, Python code, and other template syntax in the view layer can be frustrating for developers.

However, with Purepy:

  • Everything is 100% native Python code.
  • Encapsulate components to eliminate repetitive HTML code.
  • The syntax closely resembles HTML.

Documentation

Full documentation is available at https://yonlj.github.io/purepy/

Install

pip install yonlj-purepy

Basic usage

Here is a simple example that will show how to use Purepy:

from pure.html import div, a

div(
    'Hello ',
    a('Python').href('https://www.python.org')
).class_name('container').style('background: #fff;').data_key('primary').to_print()

The above code will output:

<div class="container" style="background: #fff;" data-key="primary">Hello <a href="https://www.python.org">Python</a></div>

Component

You can use Purepy to encapsulate repeated code snippets into a functional component, which looks a lot like a React functional component:

from pure.html import div, h2, p, a

# Function component
def Card(props):
    title = props.get('title', '')
    content = props.get('content', '')
    link = props.get('link', '#')

    return div(
        h2(title).class_name('card-title'),
        p(content).class_name('card-content'),
        a('Read more').href(link).class_name('card-link')
    ).class_name('card')

# Usage
Card({
    'title': 'Welcome to Purepy',
    'content': 'A Python templating engine inspired by React',
    'link': 'https://github.com/YonLJ/purepy'
}).to_print()

Features

  • Pure Python: Everything is 100% native Python code
  • Component-based: Create reusable components like React
  • HTML-like syntax: Familiar syntax for web developers
  • Type hints support: Full type hints for better IDE support
  • Zero dependencies: No external dependencies required
  • SVG support: Built-in SVG element support
  • Lightweight: Small footprint and fast performance

Examples

For more usage examples see here.

Development

Setup development environment

git clone https://github.com/YonLJ/purepy.git
cd purepy
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -e ".[dev]"

Run tests

pytest

Code formatting

black pure tests

License

MIT © YonLJ

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

yonlj_purepy-1.0.2.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

yonlj_purepy-1.0.2-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file yonlj_purepy-1.0.2.tar.gz.

File metadata

  • Download URL: yonlj_purepy-1.0.2.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for yonlj_purepy-1.0.2.tar.gz
Algorithm Hash digest
SHA256 b5fc34b2f55987e158dba89a5f60d90816d4664612f4525d34f1a3e36f00b3ae
MD5 a339434ac1ef9b202fe8963fe41356a8
BLAKE2b-256 b8cf6830dfb9274415e8d482352cc508a42db310ff4f52f6740272deed49f819

See more details on using hashes here.

File details

Details for the file yonlj_purepy-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: yonlj_purepy-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for yonlj_purepy-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7fbc5ed631646127ef602533e0412053c2125e472ece68317bb618ba5ff4c6d4
MD5 74d5c52e1abf3ea89598adc84f355fe3
BLAKE2b-256 4e5f381686707d2ba0c3e019bdde0f50151e99f58816c8c0ce226fa84bdc92e6

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