Skip to main content

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 rendering
  • p-else-if: Alternative condition
  • p-else: Fallback content
  • p-for: List rendering
  • p-key: Unique key for list items
  • p-bind: Dynamic attribute binding
  • p-text: Text content binding
  • p-html: HTML content binding
  • p-show: Conditional display
  • p-on: Event handling
  • p-model: Two-way data binding
  • p-pre: Skip compilation
  • p-once: Render once
  • p-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

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

fleetvue-0.1.2.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

fleetvue-0.1.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

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

Hashes for fleetvue-0.1.2.tar.gz
Algorithm Hash digest
SHA256 64d738a541c5815ae74ac149dcb12bf421102dbcd046a400336d060ba256a0eb
MD5 a08cf0d2386c4308b4e12f4972a4690b
BLAKE2b-256 74adfc52a6d68d8c5da62aa42292be4be13e904664151909f4046f59c2fc5e6f

See more details on using hashes here.

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

Hashes for fleetvue-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 61c07c254e5419c21801e789d4bb4c5d8e9d6f2fc291abdbdc2bfec4a2d8fe6c
MD5 541dc9bd6f5d3cacd8d16864535c91a8
BLAKE2b-256 49ee6d06aa3f495b098671efda796bc6baabfea58adb20e942b06edbb9a5c97f

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