Skip to main content

A Python package for creating and manipulating HTML components. It is working similar to React.js, but in Python

Project description

Seamless

PyPI version

test

Seamless is a Python package for creating and manipulating HTML components. It is working similar to React.js, but in Python.

Docs

Installation

pip install python-seamless

Usage

from seamless import Div, H1, P, Component, Style

class MyComponent(Component):
  def render(self):
    return Div(
      H1(
        "Hello, World!",
        style=Style(
          color="#33343c"
        ),
      ),
      P(
        "Welcome to Seamless!"
      ),
      style=Style(
        text_align="center"
      )
    )
from .components import MyComponent
from seamless.renderer import render

@app.get("/")
def hello_world():
  return render(MyComponent())

Server actions

It's possible to pass a python function as component props.

The current version works with ASGIApp.

class Person(Component):
  def __init__(self, name: str, age: float):
    self.age = age
    self.name = name

  def render(self):
    return Form(
      Div(f"Update the age for {name}"),
      Label(
        "Age: ",
        html_for="age"
      ),
      Input(
        type="text",
        on_change=self.set_age
      ),
      Button(
        "Submit Age",
        type="submit"
      ),
      on_submit=self.save_age
    )

  def set_age(self, event_data: ChangeEvent):
    self.age = event_data.value

  def save_age(self, event_data: SubmitEvent):
    user = get_user()
    user.age = self.age
    save(user)

To call a function on the server include this script in your file

<script src="/socket.io/static/main.js"></script>

Import the middleware and mount it to your app

from fastapi import FastAPI
from seamless.middlewares import ASGIMiddleware as SeamlessMiddleware

app = FastAPI()
app.add_middleware(SeamlessMiddleware)

You can pass the following config to the middleware to change the socket path of all seamless endpoints.

app.add_middleware(
  SeamlessMiddleware,
  socket_path="/my/custom/path"
)

Actions use socket.io to communicate between server and client.

TODO

  • Add detailed documentation
  • Add more tests
  • Add support for http actions

Contributing

Feel free to open an issue or a pull request.

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

python_seamless-0.8.0.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

python_seamless-0.8.0-py3-none-any.whl (44.8 kB view details)

Uploaded Python 3

File details

Details for the file python_seamless-0.8.0.tar.gz.

File metadata

  • Download URL: python_seamless-0.8.0.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for python_seamless-0.8.0.tar.gz
Algorithm Hash digest
SHA256 9029456e3c16b4f302aa27153ca720a2e6d6f7fe2a1a6ecc2e63b3113d478460
MD5 9ed824a5407d74516988da8d9d846218
BLAKE2b-256 c6e0760d58a50ab509a6561807684bdc9025b7702398f94c18c34d39f3ef1f17

See more details on using hashes here.

File details

Details for the file python_seamless-0.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_seamless-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f213390e3b2ed9e339fd48dbe6858b254cc8be50e3f02f088c43ad70d085ff5
MD5 ce1277bbf4673e4143b03d865c551746
BLAKE2b-256 24eec83fa7c61deb96b6ec2f9a9d1ce4089b3b80223a229088f79d99d5819cdf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page