Skip to main content

Teloce-Py

Teloce-Py logo

Build interactive Python apps with .vel components. No Node.js required.

PyPI version MIT license Documentation

Teloce-Py is a UI compiler for Python web applications. It compiles .vel single-file components into browser JavaScript, scoped CSS, and server-rendering instructions. The compiler takes care of the UI; your Python framework (Flask, FastAPI, Django, or Flaxon) keeps handling routes, APIs, databases, auth, and security.

Features

  • UI compiler: Compile .vel components into optimized browser assets and server-rendering instructions.
  • Single-file components: Template, script, and scoped style in one .vel file.
  • Bring your own backend: Works with Flask, FastAPI, Django, and Flaxon.
  • No Node.js: Production builds use MinifyJS, a native esbuild engine bundled in the wheel.
  • Fast builds: Tree shaking, mangling, code splitting, source maps, and hashed assets.
  • Server-side rendering (SSR): Render component output on the Python server, then hydrate it in the browser.
  • Partial Prerendering (PPR): Send an HTML shell first and stream deferred regions as their Python loaders finish.
  • Hydration: Turn server-rendered component output into interactive browser UI.

Teloce Ecosystem

Teloce is designed to support both Python-based application development and JavaScript-based workflows.

Teloce-Py

Teloce-Py is the Python implementation. It lets developers build applications using .vel single-file components without requiring Node.js.

It is a UI compiler, not a Python web framework. It handles component compilation, scoped styles, browser assets, production builds, SSR, hydration, and PPR while your Python framework remains in control of the application.

The server renderer uses a validated render program rather than executing component JavaScript in Python. For PPR, <Defer> boundaries let the host flush the page shell and stream independently loaded regions.

Teloce-NPM

Teloce-NPM is the companion npm project for the Teloce ecosystem.

It provides npm-based tooling and packages for developers working with Teloce and JavaScript-based projects. It complements Teloce-Py by supporting workflows outside the Python package environment.

Explore Teloce-NPM:

The Three.js example demonstrates using Teloce-NPM in a project with Three.js.

Together, Teloce-Py and Teloce-NPM provide different ways to work with the Teloce ecosystem.

Getting Started

This walkthrough builds a small counter with an animated 2D sun. The count lives on the Flask server, and the component reads and updates it through Teloce's built-in http network API. The same component works with any backend that returns JSON.

Install:

python -m pip install teloce-py Flask

Create static/js/App.vel:

<script>
import { http } from "teloce/runtime";

export default {
  data() { return { count: 0, busy: false, error: "" }; },
  mounted() { this.load(); },
  methods: {
    async request(send) {
      this.busy = true;
      try {
        const res = await send();
        if (res.ok) { this.count = res.data.count; this.error = ""; }
        else this.error = "Request failed (" + res.status + ")";
      } catch (e) {
        this.error = "Server unreachable";
      }
      this.busy = false;
    },
    load() { return this.request(() => http.get("/api/count")); },
    increment() { return this.request(() => http.post("/api/count/increment")); }
  }
};
</script>

<template>
  <main class="scene">
    <div class="sun" aria-hidden="true">
      <div class="rays"></div>
      <div class="core"></div>
    </div>
    <button @click="increment" :disabled="busy">Clicked {{ count }} times</button>
    <p class="error" v-if="error">{{ error }}</p>
  </main>
</template>

<style scoped>
.scene { display: grid; justify-items: center; gap: 1.5rem; padding: 2rem; font-family: system-ui, sans-serif; }
.sun { position: relative; width: 120px; height: 120px; }
.core { position: absolute; inset: 24px; border-radius: 50%; background: #ffc83d; box-shadow: 0 0 24px #ffb300; animation: pulse 3s ease-in-out infinite; }
.rays { position: absolute; inset: 0; border-radius: 50%; background: repeating-conic-gradient(#ffb300 0 8deg, transparent 8deg 30deg); mask: radial-gradient(circle closest-side, transparent 62%, #000 64%); animation: spin 14s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { transform: scale(1.08); } }
@media (prefers-reduced-motion: reduce) { .core, .rays { animation: none; } }
.error { color: #b42318; }
</style>

Create app.py:

from pathlib import Path
from flask import Flask, jsonify, render_template
from teloce.build import build_project

ROOT = Path(__file__).parent
build_project(ROOT, out_dir=ROOT / "dist", options={"dev": True})

app = Flask(__name__, static_folder="dist/static", static_url_path="/static")
count = 0

@app.get("/")
def home():
    return render_template("app.html")

@app.get("/api/count")
def get_count():
    return jsonify(count=count)

@app.post("/api/count/increment")
def increment():
    global count
    count += 1
    return jsonify(count=count)

if __name__ == "__main__":
    app.run(debug=True)

Create templates/app.html:

<!doctype html>
<html>
  <body>
    <div id="app"></div>
    <script type="module">
      import { mount } from "{{ url_for('static', filename='js/App.js') }}";
      mount("#app");
    </script>
  </body>
</html>

Run it and open http://127.0.0.1:5000:

python app.py

Click the button: each click sends POST /api/count/increment, and reloading the page keeps the count because it is stored on the server.

How the http API works

  • import { http } from "teloce/runtime" gives you a fetch client. The build rewrites that import to the right path for each component.
  • http.get(url) and http.post(url, body) return { data, status, ok }. A non-2xx status resolves, so check res.ok. Only transport failures (timeout, offline, abort) throw a NetworkError, which is why the example wraps the call in try/catch.
  • JSON bodies are encoded for you, requests use credentials: "same-origin", and the default timeout is 10 seconds. Retries, interceptors and CSRF-token support are opt-in via http.setConfig(...).
  • The counter is an in-memory demo: it is shared by every visitor and resets when the server restarts. For a real app, store it in a database and protect writes with your framework's CSRF checks.

Teloce also ships action (named server calls) and socket (WebSocket channels). See the Network API guide.

Editor Support

Optional but recommended: install the Teloce extension for VS Code. It adds syntax highlighting, diagnostics, autocomplete, hover information, formatting, and snippets for .vel files.

code --install-extension Flaxon-vscode.teloce-vscode

Or open the Extensions panel (Ctrl+Shift+X / Cmd+Shift+X), search for Teloce, and click Install. Teloce-Py works without it.

Project Structure

my-app/
├── app.py
├── teloce.config.json
├── static/
│   └── js/
│       └── App.vel       # Your source
├── templates/
│   └── app.html          # HTML shell with #app mount
└── dist/                 # Generated, never edit by hand

Production Build

teloce lint --strict
teloce build --source-map --hash-assets --bundle --report

Teloce strips common TypeScript syntax during compilation. The optional teloce typecheck command checks scripts and supported template expressions with PyTSCheck.

Documentation

Status

Teloce-Py is in beta. Pin your version and test generated assets on your target framework and platform.

License

MIT

Runtime Contributor Checks

The JavaScript runtime uses JSDoc types with a development-only checker:

npm ci --ignore-scripts
npm run typecheck

See coverage and workflow.

Runtime files stay .js; Python application users do not need Node or TypeScript.

Optional Component Type Checking

On Python 3.11+, install:

pip install "teloce-py[typecheck]"

Then run:

teloce typecheck ui

Or use JSON output for CI:

teloce typecheck ui --json

This checks TypeScript script blocks, .ts files/declarations, and supported template expressions using the bundled PyTSCheck compiler.

See the type-checking guide for API examples, diagnostic locations, optional dependency handling, and prototype limits.

Plain JavaScript components are skipped. Project tsconfig settings and dependency declarations are inherited automatically; object-style props infer supported constructor types. Props passed to statically imported TypeScript children are validated. Array-style prop values, dynamic children, and some import forms remain limited.

You can also explore this Teloce-NPM Three.js example.

Metadata

Release files for teloce-py 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for teloce-py 0.4.0
File Size Uploaded Provenance Actions
teloce_py-0.4.0.tar.gz 412.0 kB Without provenance Details for teloce_py-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for teloce-py 0.4.0
File Interpreter ABI Platform Actions
teloce_py-0.4.0-py3-none-any.whl Python 3 none any Details for teloce_py-0.4.0-py3-none-any.whl

Total release size: 878.3 kB

Release files / teloce_py-0.4.0.tar.gz

Download URL teloce_py-0.4.0.tar.gz
Size 412.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cea05c1c09c65fb21ea448cb1852bcd97ea06824a8f3b5429c9f309d5dbcc015
BLAKE2b-256 checksum
How to use checksums
a71fc465fecea43c4e80bfa1d8e35d567585b90ffdf475277864e8fbdc109a40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / teloce_py-0.4.0-py3-none-any.whl

Download URL teloce_py-0.4.0-py3-none-any.whl
Size 466.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f58a7cf3ad3ea3e3d4dc67d52ed093dfc2004b183ee638bab0cd59a04b3eb6c
BLAKE2b-256 checksum
How to use checksums
df4d3736b4f694f2ef28ed6537a885f0f19a85a31a1bff6189a4b7844de33df4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Security for teloce-py 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page