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.

We have detailed documentation here

Installation

pip install python-seamless

Usage

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

class MyComponent(Component):
  def render(self):
    root_style = StyleObject(color="#33343c")
    return Div(style=div_style)(
      H1(
        "Hello, World!",
      ),
      P(
        "Welcome to Seamless!"
      ),
    )
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(on_submit=self.save_age)(
      Div(f"Update the age for {name}"),
      Label(html_for="age")(
        "Age: "
      ),
      Input(
        type="text",
        on_change=self.set_age
      ),
      Button(type="submit")(
        "Submit 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="https://cdn.jsdelivr.net/npm/@python-seamless/core@0.8.4/umd/seamless.init.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.9.2.tar.gz (33.7 kB view details)

Uploaded Source

Built Distribution

python_seamless-0.9.2-py3-none-any.whl (97.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_seamless-0.9.2.tar.gz
  • Upload date:
  • Size: 33.7 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.9.2.tar.gz
Algorithm Hash digest
SHA256 b8676e714e5ece1c06fb5e3a424c649c64659e509d8c7db7bea32dfae7e441e4
MD5 a52d55d4d1c1fc6b8228ad6febfa72c6
BLAKE2b-256 4fa9a01b35384ebd4833587e56a240bbff6f75dd8160128464285691711767e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_seamless-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f5dcf7425925ffb7981f65d4b97e8e255b0b8cff7af4bb86eb8f602e75ed3eab
MD5 5f30a2078fbaedcb1c3da872ec8ca6ee
BLAKE2b-256 a7817acc885a372c574bec707c8839cd606b312797583a7e6b1038b3f109674c

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