Skip to main content

Gladius aka "gladius" is a full-stack web framework facilitating web application development exclusively in pure Python, eliminating the need for HTML, CSS, or JavaScript. It is built for those who prefer to use Python, providing access to features typically found in modern web frameworks.

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

# list packages from https://npmjs.com, and files that need to be transpiled
npm_packages = {
    '@picocss/pico': ['css/pico.css'],
    'nprogress': ['nprogress.js', 'nprogress.css'],
}

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

# client-side code, never executed on server-side
def load_cb():
    # this code is run on client-side only
    from pyscript import document, window, when # type: ignore
    from pyscript.web import page, button # type: ignore

    # import nprogress package
    # https://github.com/rstacruz/nprogress
    from pyscript.js_modules.nprogress import default as NProgress # type: ignore

    # get main element and append a button
    main = page['main'][0]

    main.append(
        button('Hello from PyScript', id='hello-button'),
    )

    # get button element
    btn = page['#hello-button'][0]
    clicked: int = 0

    # listen for the click event on the button element
    # and keep updating how many times it was clicked
    # additionally start/stop NProgress
    @when('click', btn)
    def my_button_click_handler(event):
        global clicked
        NProgress.start()
        clicked += 1
        btn.innerText = f'The button has been clicked {clicked} time{"" if clicked == 1 else "s"}!'
        NProgress.done()


# create page, body, main, h1 elements
# and attach client-side script which pysciprt will execute once page is loaded
with page:
    with g.body(x_data=None):
        with g.main(class_='container'):
              g.h1('Hello world!')

        # attach client-side python script
        g.script(load_cb)


# run server
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:

watchmedo auto-restart --directory=./ --pattern="*.py" --recursive -- python -B app.py

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.2.0.tar.gz (35.8 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.2.0-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gladius-0.2.0.tar.gz
  • Upload date:
  • Size: 35.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/6.12.10-arch1-1

File hashes

Hashes for gladius-0.2.0.tar.gz
Algorithm Hash digest
SHA256 65a4ed702776d174c945c377b47b84d15fdd6c5b6e00adc151405060d9896c0f
MD5 a081f042a3d12b30d8a21d4b65b1a519
BLAKE2b-256 0d1b5ef8e9a268ab9b8c9f95423b46cf40eb697a17fb4074da852ae5c764831d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for gladius-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 74523613f285b4feac0414dae75ed7153e58bf23be6b639187b9f25b93ddd08d
MD5 12fdde673d49cf3d68dd72595c1f3cea
BLAKE2b-256 d814ad3ea757dd65e7d926be5cbca934cf408a8acc0e00349755848001930e41

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