Skip to main content

PyBlade is a lightweight template engine for Python, initially designed for Django. Inspired by Laravel's Blade and Livewire, it simplifies dynamic template creation with developer-friendly @-based directives and component support, all while prioritizing security.

Project description

PyBlade

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.

Roadmap

  • 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

Features

  • 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.

Documentation

Comprehensive documentation is available at pyblade.vercel.app, covering:

  • Getting started guide
  • Template syntax
  • Component system
  • Best practices
  • API reference

Installation

Install PyBlade via pip:

pip install pyblade

File Extension

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.

IDE Support

Available Now

  • PyBlade IntelliSense in the VS Code marketplace with support of:
    • Syntax highlighting
    • Snippets
    • Auto-completion for directives and components

Coming Soon

  • JetBrains IDEs (PyCharm, WebStorm, etc.)
  • Sublime Text
  • Atom

Basic Usage

<!-- 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

Security

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.

Contributing

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:

License

This project is licensed under the MIT License – see the LICENSE file for details.

Acknowledgements

  • 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 ! 🚀

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

pyblade-0.2.0.tar.gz (90.1 kB view details)

Uploaded Source

Built Distribution

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

pyblade-0.2.0-py3-none-any.whl (115.1 kB view details)

Uploaded Python 3

File details

Details for the file pyblade-0.2.0.tar.gz.

File metadata

  • Download URL: pyblade-0.2.0.tar.gz
  • Upload date:
  • Size: 90.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.11.2 Linux/6.12.32-amd64

File hashes

Hashes for pyblade-0.2.0.tar.gz
Algorithm Hash digest
SHA256 51f032015c226e3ed8539f67c3af1c7d7f731d6dd95dee39dac04f6d1f92623f
MD5 f3600a9e1f0641a7e877301ad8906b5c
BLAKE2b-256 eb145fad69a428c1b10fa15f54f56dae109ba7f621c2b9f228108832af52d451

See more details on using hashes here.

File details

Details for the file pyblade-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyblade-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 115.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.11.2 Linux/6.12.32-amd64

File hashes

Hashes for pyblade-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ad368d1fddbf86067a6459f7c6882a9780e82750ef2a85e72d5da06c80fd701
MD5 c32269c3900fda67f08d3c8389dfa3b5
BLAKE2b-256 316233fa722ab27a3b713c8a16363dfbdddeaa406456f2bb614c58a72dc27b62

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