Skip to main content

Gladius is a library facilitating web application development exclusively in pure Python

Project description

gladius

Downloads Supported Versions License: MIT

Gladius aka "gladius" is a library facilitating web application development exclusively in pure Python, eliminating the need for HTML, CSS, or JavaScript/TypeScript.

Built for developers who want to leverage Python across the entire stack, Gladius provides access to modern web framework features while mirroring patterns familiar to full-stack Python developers. These developers often blend Python on the server with traditional JavaScript/CSS tools for frontend UI—Gladius simplifies this workflow by enabling Python-driven UI development, reducing context-switching between languages.

For traditional frontend developers, Gladius offers a comfortable transition by exposing all standard Web APIs available in browsers. This ensures compatibility with existing NPM packages (from npmjs), allowing seamless integration of JavaScript libraries when needed.

By unifying frontend and backend development under Python, Gladius delivers a cohesive, intuitive experience—ideal for developers seeking a Python-centric approach without sacrificing access to the broader web ecosystem.

Install

pip install gladius[all]

Hello World

Create app.py file with content:

from aiohttp import web
from gladius.starter import create_aiohttp_app

# required npm packages
npm_packages = {
    '@picocss/pico': ['css/pico.css'],
    'nprogress': ['nprogress.js', 'nprogress.css'],
}

# client-side click handler
def ready():
    from pyscript import when
    from pyscript.web import page
    from pyscript.js_modules.nprogress import default as NProgress

    btn = page['#hello-button'][0]  # get server-created button
    clicked = 0                     # track clicks

    @when('click', btn)
    def on_click(event):
        global clicked
        NProgress.start()
        clicked += 1
        btn.innerText = f'Clicked {clicked} time{"s" if clicked !=1 else ""}!'
        NProgress.done()

# create simple aiohttp web server
g, page, app = create_aiohttp_app(
    npm_packages=npm_packages, # type: ignore
    use_pyscript=True,
    use_micropython=True,
    ready=ready,
)

# server-side structure
with page:
    with g.body(x_data=None):
        with g.main(class_='container'):
            g.h1('Gladius Demo')
            g.button('Click me!', id='hello-button')    # create button on server

# start application
if __name__ == '__main__':
    web.run_app(app, host='0.0.0.0', port=5000)

Run python app with simple server in background:

python -B app.py

Or, in case you want to rebuild on code change:

python -B -u -m gunicorn --reload --bind '0.0.0.0:5000' --timeout 300 --workers 1 --worker-class aiohttp.GunicornWebWorker 'app:app'

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

gladius-0.3.1.tar.gz (37.4 kB view details)

Uploaded Source

Built Distribution

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

gladius-0.3.1-py3-none-any.whl (36.2 kB view details)

Uploaded Python 3

File details

Details for the file gladius-0.3.1.tar.gz.

File metadata

  • Download URL: gladius-0.3.1.tar.gz
  • Upload date:
  • Size: 37.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.9 Linux/6.13.3-arch1-1

File hashes

Hashes for gladius-0.3.1.tar.gz
Algorithm Hash digest
SHA256 3bf12c7ed831c40cc0f44cd472e662c3ddbb5682d69bd8fbbb6162e8588b33bd
MD5 970142dc8ac0befcf37a6647b7074a22
BLAKE2b-256 629ad45b023542cd9f9aa454fb0a85f7561a6db5c6569a41677bc1d5aa6ae6f7

See more details on using hashes here.

File details

Details for the file gladius-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: gladius-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 36.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.9 Linux/6.13.3-arch1-1

File hashes

Hashes for gladius-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5013fc343fe8161c37d9cbbe3cfa3dd5f0cf1a7a1e8a9ad7918a267e8d70ef72
MD5 8fc1e5b77b4ad0d7cad39401cf17d738
BLAKE2b-256 1ef6702e4bf7ce0ed7a7b478ba5a2d2c8b467388f238a99ccbb20d166e7a3aaa

See more details on using hashes here.

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