Skip to main content

Full stack component framework for Django using Alpine.js

Project description

Tetra

Full stack component framework for Django using Alpine.js

Tetra is a new full stack component framework for Django, bridging the gap between your server logic and front end presentation. It uses a public shared state and a resumable server state to enable inplace updates for components. It also encapsulates your Python, HTML, JavaScript and CSS into one file or directory for proximity of related concerns.

Documentation

Too much for a README. There's a Documentation page.

There is also a shortcut to some examples.

Installation

As usual:

uv pip install tetra

But wait, this isn't all. Tetra needs some customization in your Django project.

Read more at Installation docs

Short Overview

For the impatient: here's a short example video that shows what Tetra is capable of:

https://github.com/user-attachments/assets/137c53af-1fc2-48c5-9c53-a007fbad7874

This is done using simple and concise code in one component, rendered in your template with just {% InfoCard / %}. No page reload needed.

from tetra import Component, public

class InfoCard(Component):
    title: str = "I'm so excited!"
    content: str = "We got some news for you."
    name: str = public("")

    @public
    def close(self):
        self.client._removeComponent()

    @public
    def done(self):
        print("User clicked on OK, username:", self.name)
        self.content = f"Hi { self.name }! No further news."

    template = """
    <div class="card text-white bg-secondary mb-3" style="max-width: 18rem;">
      <div class="card-header d-flex justify-content-between">
        <h3>Information</h3>
        <button class="btn btn-sm btn-warning" @click="_removeComponent(
        )"><i class="fa fa-x"></i></button>
      </div>
      
      <div class="card-body">
        <h5 class="card-title">{{ title }}</h5>
        <p class="card-text">
          {{ content }}
        </p>
        <p x-show="!name">
          Enter your name below!
        </p>
        <p x-show="name">
            Thanks, {% livevar name %}
        </p>
        <div class="input-group mb-3">

          <input 
            type="text" 
            class="form-control" 
            placeholder="Your name" 
            @keyup.enter="done()"
            x-model="name">
        </div>
        <button 
            class="btn btn-primary" 
            @click="done()" 
            :disabled="name == ''">
            Ok
        </button>
      </div>
      
    </div>
    """

What does Tetra do exactly?

Django on the backend, Alpine.js in the browser : Tetra combines the power of Django with Alpine.js to make development easier and quicker.

Component encapsulation : Each component combines its Python, HTML, CSS and JavaScript in one place for proximity of related code.

Resumable server state : The components' full server state is saved between public method calls. This state is encrypted for security.

Public server methods : Methods can be made public, allowing you to easily call them from JS on the front end, resuming the component's state.

Shared public state : Attributes can be decorated to indicate they should be available in the browser as Alpine.js data objects.

Server "watcher" methods : Public methods can be instructed to watch a public attribute, enabling reactive re-rendering on the server.

Inplace updating from the server : Server methods can update the rendered component in place. Powered by the Alpine.js morph plugin.

Component library packaging : Every component belongs to a "library"; their JS & CSS is packed together for quicker browser downloads.

Components with overridable slots : Components can have multiple {% slot(s) %} which can be overridden when used.

JS/CSS builds using esbuild : Both for development (built into runserver) and production your JS & CSS is built with esbuild.

Automatic Js Source Maps : Source maps are generated during development so that you can track down errors to the original Python files.

Syntax highlighting with type annotations : Tetra uses type annotations to syntax highlight your JS, CSS & HTML in your Python files with a VS Code plugin

Forms : FormComponents can act as simple replacements for Django's FormView, but due to Tetra's dynamic nature, a field can e.g. change its value or disappear depending on other fields' values.

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

tetra-0.8.5.tar.gz (174.6 kB view details)

Uploaded Source

Built Distribution

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

tetra-0.8.5-py3-none-any.whl (189.2 kB view details)

Uploaded Python 3

File details

Details for the file tetra-0.8.5.tar.gz.

File metadata

  • Download URL: tetra-0.8.5.tar.gz
  • Upload date:
  • Size: 174.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"KDE neon","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tetra-0.8.5.tar.gz
Algorithm Hash digest
SHA256 79ae0e4e65c7246d1054ca88c4b35db80a5753c3c6984bc880b7696794fb5a42
MD5 8781ac28da23be4d915a9df4948397c0
BLAKE2b-256 07e62b1bae50630b742f600bcc245a89fd126f8ef398589b56529721ece73dc8

See more details on using hashes here.

File details

Details for the file tetra-0.8.5-py3-none-any.whl.

File metadata

  • Download URL: tetra-0.8.5-py3-none-any.whl
  • Upload date:
  • Size: 189.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"KDE neon","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tetra-0.8.5-py3-none-any.whl
Algorithm Hash digest
SHA256 93d225acef420790c0b8deef7a02421e9a5a288a0e5432a6f589119f3c891b90
MD5 6d02cb0dc99fa21f422149419f2d06b0
BLAKE2b-256 1ce26c66a57779c7df25d5439c0534a4f2a58a252305f6798e009d58a19cda7b

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