Skip to main content

A full-stack python reactive web components framework

Project description

Basis: Full-Stack Reactive Python Framework

Basis is an experimental full-stack web framework for building interactive, stateful web applications entirely in Python. It runs FastAPI on the server for initial Server-Side Rendering (SSR) and PyScript in the browser for Client-Side Hydration (CSH), providing a reactive, component-based developer experience with no JavaScript.


Quickstart

1. Installation

Install the framework alongside FastAPI and Uvicorn:

pip install fastapi uvicorn basis-framework

2. Create a minimal Basis App (app.py)

from basis.shared.component import Basis, Component

app = Basis()

@app.entrypoint
class HelloBasis(Component):
    """
    <div><input bind="{name}" placeholder="Type your name..." />Hello {name}!</div>
    """

    name = "World"

3. Run the Development Server

uvicorn app:app --reload

Navigate to http://localhost:8000 to interact with the application.


Core Philosophy

  • Python Everywhere — Write backend services, business logic, component templates, and client-side reactive state in pure Python.
  • Native Custom Elements — Components map to standard hyphenated HTML custom tags, keeping styling and markup aligned with web standards.
  • Fine-Grained Reactivity — No Virtual DOM. Basis uses a Directed Acyclic Graph (DAG) to track dependencies and update only the targeted DOM nodes when state changes.
  • Isomorphic Hydration — Server renders fully-formed, SEO-friendly HTML, which the client hydrates in-place without flashes of unstyled content or layout shifts.

Key Features

1. DAG-Based Reactivity

Basis manages state propagation using a Directed Acyclic Graph (DAG) with three node types:

  • StateNode: The root state sources (raw component attributes).
  • ComputedNode: Derived values that cache results and recalculate only when their upstream dependencies change.
  • EffectNode: Leaves of the graph representing DOM updates (bindings) that react to state or computed mutations.

2. Computed Properties

Use the @computed decorator to define derived state. Basis parses the function's Abstract Syntax Tree (AST) to automatically detect dependency attributes:

@computed
def full_name(self):
    return f"{self.first_name} {self.last_name}"

3. Smart Keyed Reconciliation

The SmartKeyedLoopBinding uses a Longest Increasing Subsequence (LIS) algorithm to dynamically reorder and update DOM list items in-place. This preserves browser input focus, scroll position, and CSS animations during list sorting or updates.

4. Cross-Boundary References

The template braces syntax supports special prefixes to bind reactive state across boundaries:

  • $store_name.field: Subscribes directly to a shared, global Store instance.
  • #component_id.field: Subscribes to the attribute of another component in the DOM by its HTML id.
<p>Store Value: {$session.count}</p>
<child-comp id="child"></child-comp>
<p>Child status: {#child.status}</p>

Codebase Structure

The framework codebase is structured as follows:

  • basis/src/basis/shared/dag.py — The reactive dependency graph engine.
  • basis/src/basis/shared/bindings.py — DOM bindings (Text, Attribute, Loops, Slots).
  • basis/src/basis/shared/base_component.py — Base component lifecycle, state mapping, and setup.
  • basis/src/basis/client/ — Browser-side component mounting and PyScript entrypoint.
  • basis/src/basis/server/ — FastAPI application wrapper, static file servers, and RPC router.

Documentation

For a comprehensive guide, architecture diagrams, and detailed API breakdowns of stores, bindings, and hydration, browse the files in the docs/ directory starting with docs/index.md.

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

basis_framework-0.1.0.tar.gz (7.0 MB view details)

Uploaded Source

Built Distribution

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

basis_framework-0.1.0-py3-none-any.whl (7.1 MB view details)

Uploaded Python 3

File details

Details for the file basis_framework-0.1.0.tar.gz.

File metadata

  • Download URL: basis_framework-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for basis_framework-0.1.0.tar.gz
Algorithm Hash digest
SHA256 638a39de2501fa90ddf2833cc50f1f64862653c7c704b6ff515ac25899d60993
MD5 c4d30a6899e9f7f32eef4d874c880171
BLAKE2b-256 4e5ac84c76b10c943aae8fce21eab740a89d6a3f5be8df0c3e70c58badd00411

See more details on using hashes here.

Provenance

The following attestation bundles were made for basis_framework-0.1.0.tar.gz:

Publisher: publish.yml on bassio/basis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file basis_framework-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for basis_framework-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f24c48fadaca3c7c49273ea2cc7712aa9ad84caf887e34984e326b56c737e83
MD5 0bc310ea520c1b3a28902c8c9c547fb6
BLAKE2b-256 78064403cd0a875dc395761ef54f631e881492e5d7e5e21b68f62f1802e84b85

See more details on using hashes here.

Provenance

The following attestation bundles were made for basis_framework-0.1.0-py3-none-any.whl:

Publisher: publish.yml on bassio/basis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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