A Vue.js-like templating engine using Jinja2 for Python
Project description
FleetVue
A powerful Vue.js-like templating engine for Python using Jinja2. FleetVue brings the familiar Vue.js syntax to Python while leveraging the robust features of Jinja2.
Features
- Vue.js-like template syntax with
p-directives - Full Jinja2 template engine capabilities
- Support for async rendering
- Sandboxed environment for security
- BeautifulSoup4 for HTML parsing
- Template caching for better performance
- Custom filters support
Installation
pip install fleetvue
Quick Start
from fleetvue import render_template
template = """
<div p-if="show">
<p p-text="message"></p>
</div>
<ul>
<li p-for="item in items" p-key="item.id">{{ item.name }}</li>
</ul>
"""
data = {
'show': True,
'message': 'Hello, World!',
'items': [{'id': 1, 'name': 'Item 1'}, {'id': 2, 'name': 'Item 2'}]
}
output = render_template(template, data)
print(output)
Available Directives
p-if: Conditional renderingp-else-if: Alternative conditionp-else: Fallback contentp-for: List renderingp-key: Unique key for list itemsp-bind: Dynamic attribute bindingp-text: Text content bindingp-html: HTML content bindingp-show: Conditional displayp-on: Event handlingp-model: Two-way data bindingp-pre: Skip compilationp-once: Render oncep-cloak: Hide until compiled
Advanced Usage
Custom Engine Configuration
from fleetvue import VueJinjaEngine
# Create a custom engine instance
engine = VueJinjaEngine(
sandboxed=True, # Use sandboxed environment for security
enable_async=True # Enable async support
)
# Add custom filters
engine.env.filters['uppercase'] = lambda x: str(x).upper()
# Use the engine
template = '<h1 p-text="title | uppercase"></h1>'
data = {'title': 'Hello World'}
output = engine.render_template(template, data)
Async Rendering
import asyncio
from fleetvue import VueJinjaEngine
async def main():
engine = VueJinjaEngine(enable_async=True)
template = '<div p-text="message"></div>'
data = {'message': 'Hello World'}
output = await engine.render_template_async(template, data)
print(output)
asyncio.run(main())
Sandboxed Environment
from fleetvue import VueJinjaEngine
engine = VueJinjaEngine(sandboxed=True)
output = engine.render_template(template, data)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Vishnu Prasad - GitHub
Acknowledgments
- Jinja2 for the powerful templating engine
- BeautifulSoup4 for HTML parsing
- Vue.js for the inspiration and syntax
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 Distribution
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 fleetvue-0.1.2.tar.gz.
File metadata
- Download URL: fleetvue-0.1.2.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64d738a541c5815ae74ac149dcb12bf421102dbcd046a400336d060ba256a0eb
|
|
| MD5 |
a08cf0d2386c4308b4e12f4972a4690b
|
|
| BLAKE2b-256 |
74adfc52a6d68d8c5da62aa42292be4be13e904664151909f4046f59c2fc5e6f
|
File details
Details for the file fleetvue-0.1.2-py3-none-any.whl.
File metadata
- Download URL: fleetvue-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61c07c254e5419c21801e789d4bb4c5d8e9d6f2fc291abdbdc2bfec4a2d8fe6c
|
|
| MD5 |
541dc9bd6f5d3cacd8d16864535c91a8
|
|
| BLAKE2b-256 |
49ee6d06aa3f495b098671efda796bc6baabfea58adb20e942b06edbb9a5c97f
|