Server-driven UI kit for Python with async support
Project description
Schorle
(pronounced as ˈʃɔʁlə) is a server-driven UI kit for Python with
async support.
Note: This project is in an early stage of development. It is not ready for production use.
Installation
pip install schorle
Usage
Take a look at the examples directory.
Concepts
We use the following approaches to handle various cases:
- Rendering HTML elements is done using Python functions.
Elements
In contrast to using templating engines, Schorle uses Python functions to create HTML elements. This approach allows for better type checking and code completion.
from schorle.text import text
from schorle.element import div
from schorle.rendering_context import rendering_context
def my_element():
with div():
text("Hey!")
with rendering_context() as ctx:
my_element()
print(ctx.to_lxml())
Although this might seem a bit complicated, in actual applications it works nicely when Elements are used inside the Components.
Components
Components are reusable parts of the UI. They are created using Python classes.
from schorle.component import Component
from schorle.element import div
from schorle.text import text
class MyComponent(Component):
def render(self):
with div():
text("Hey!")
print(
MyComponent().to_string()
)
Note that the render
method is used to define the structure of the component.
Since render
is a method, you can use all the power of Python to create dynamic components, like this:
from schorle.component import Component
from schorle.element import div, span
from schorle.text import text
class MyComponent(Component):
def render(self):
with div():
for idx in range(10):
with span():
text("Hey!") if idx % 2 == 0 else text("Ho!")
Pretty much any Python code can be used to create the structure of the component.
Running the application
Schorle application is a thin wrapper around FastAPI. To run the application,
use uvicorn
:
uvicorn examples.static:app --reload
Under the hood, Schorle uses FastAPI, so you can use all the features provided by FastAPI.
To access the FastAPI application instance, use the backend
attribute:
from schorle.app import Schorle
app = Schorle()
app.backend.add_middleware(...) # add FastAPI middleware
Dev reload
Schorle
supports dev reload out of the box. To enable it, use the --reload
flag:
uvicorn examples.todo:app --reload
On any change in the code, the server will restart automatically, and the client will re-fetch the page.
Tech stack
On the backend:
On the frontend:
- Tailwind CSS - CSS framework
- DaisyUI - Component library for Tailwind CSS
- Lucide Icons - Icon library
Optimizing the site performance
Schorle
has several features to optimize the site performance:
- Client-server communications are happening over WebSockets and inside a Worker
- CSS/JS libraries are served as brotli-compressed files
Roadmap
- Add dev reload
- Add server communication channel
- Add state (global)
- Add state at component level
- Add more elements
- Add support for icons
- Add convenient attributes API
- Add more examples
- Add tests
- Add CI/CD
- Add documentation
- Add support for Plotly-based charts
- Add support for Vega-based charts
- Refactor the imports
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file schorle-0.0.25.tar.gz
.
File metadata
- Download URL: schorle-0.0.25.tar.gz
- Upload date:
- Size: 154.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99d7971fdf372e707d97418e107c607ef64e4aa09a04363c2111d95209e369fd |
|
MD5 | 04a3f871d21eebb1272609d136a58108 |
|
BLAKE2b-256 | 0fda9072f04b56a07a85df0f4f6e132d3dad67a3e958db6ba720adddddcb64a3 |
File details
Details for the file schorle-0.0.25-py3-none-any.whl
.
File metadata
- Download URL: schorle-0.0.25-py3-none-any.whl
- Upload date:
- Size: 666.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8386bac116a2c988b16bcc7e245ad3f9b47a9a49e516dba5f88acd89dfea3e85 |
|
MD5 | 2931126d316cc36957dafcb2a2a84219 |
|
BLAKE2b-256 | 957439e1a470727f62a190c84101e44bc67ba54270ba5699eedad36b1f0e64e0 |