PyBlade is a lightweight, flexible, and efficient template engine for Python, inspired by Laravel's Blade syntax. It makes transitioning from Laravel to Django seamless by offering familiar features like components (inspired by Laravel Livewire) and a simple, intuitive syntax. Designed primarily for Django projects, PyBlade allows developers to create dynamic, interactive templates with ease, while maintaining robust security measures.
- Basic template rendering with variable interpolation
- Support for conditionals and loops
- Template inheritance, partials, and slots
- Integration with Django
- Components similar to Laravel Livewire
- Security measures
- Full documentation
- Familiar Blade-Like Syntax: Intuitive
@
-based directives for conditions, loops, and variable interpolation. - Component Support: Fully functional component system inspired by Laravel Livewire, enabling developers to create reusable, dynamic components with real-time interactivity.
- Easy Django Integration: A powerful alternative to Django's default templating engine, while maintaining seamless integration.
- Lightweight and Fast: Optimized for performance and simplicity.
- Security-Focused: Enhanced security features including:
- Automatic escaping of variables
- Safe expression evaluation
- Protection against XSS attacks
- CSRF protection for components
- Secure attribute handling
- Ideal for Laravel Developers: Designed to help Laravel developers easily understand and adapt to Django's ecosystem.
Comprehensive documentation is available at pyblade.vercel.app, covering:
- Getting started guide
- Template syntax
- Component system
- Best practices
- API reference
Install PyBlade via pip:
pip install pyblade
PyBlade uses the standard .html
file extension for templates, making it compatible with existing web development tools and workflows while maintaining familiar syntax highlighting and editor features.
- PyBlade IntelliSense in the VS Code marketplace with support of:
- Syntax highlighting
- Snippets
- Auto-completion for directives and components
- JetBrains IDEs (PyCharm, WebStorm, etc.)
- Sublime Text
- Atom
<!-- template.html -->
@extends('layouts.base')
@section('content')
<h1>Welcome, {{ user.name }}!</h1>
@if(posts)
@for(post in posts)
<article>
<h2>{{ post.title }}</h2>
<p>{{ post.content }}</p>
</article>
@endfor
@else
<p>No posts found.</p>
@endif
<!-- Interactive Component Example -->
@component('like-button', post_id=post.id)
<span>Like this post</span>
@endcomponent
@endsection
At PyBlade, we take security seriously. The template engine will automatically escape output unless explicitly marked as safe. This helps protect against Cross-Site Scripting (XSS) and ensures that user-generated content is handled securely. Additional features, such as CSRF token support and other security best practices, will be incorporated to ensure that your Django applications remain secure.
Contributions are welcome! PyBlade is an open-source project, and we invite developers from both the Django and Laravel communities to collaborate. Please refer to the Contributing Guide for more information.
PyBlade is open source and welcomes contributions! Here's how you can help:
- Core Development: Visit our PyBlade GitHub repository
- IDE Extensions: Help develop extensions for various editors
- Documentation: Improve our docs from the core repository
- Bug Reports: Submit issues on GitHub
- Feature Requests: Share your ideas through GitHub discussions
This project is licensed under the MIT License – see the LICENSE file for details.
- Inspired by Laravel's Blade template engine and Livewire components.
- Thanks to the Python, Django, and Laravel communities for their ongoing support of open-source projects.
- Special thanks to Michael Dimchuk for graciously releasing the name PyBlade on PyPI for this project. Your kindness and support for the open-source community are truly appreciated!
Let's bring the power of Blade-like templating and Livewire-like interactivity to Django ! 🚀