Skip to main content

A Pythonic base for building interactive web applications

Project description

baseweb

PyPI PyPI downloads Python CI Docs Coverage

A Pythonic base for building interactive web applications

Async/Quart Support

Version 0.5.0+ uses Quart (async) instead of Flask (sync).

  • All route handlers must be async functions
  • request.get_json() must be awaited
  • render_template() must be awaited
  • WebSocket uses python-socketio (ASGI mode)

For legacy Flask support: Use baseweb<0.5.0 or see the Migration Guide.

Installation

pip install baseweb

Quick Start

# Install baseweb and an ASGI server
pip install baseweb gunicorn uvicorn

# Run the stock baseweb application (with WebSocket support)
gunicorn -w 1 -k uvicorn.workers.UvicornWorker "baseweb:server._asgi_app"

Visit http://localhost:8000 to see baseweb in action.

Features

Feature Description
Quart Integration Pre-configured Quart application with async support
Vue.js + Vuetify Modern frontend stack ready to use
REST API Built-in Resource class for REST APIs
WebSocket Support python-socketio with ASGI for real-time communication
Authentication Built-in authentication/authorization hooks (HTTP + WebSocket)
PWA Support Progressive Web App capabilities

Usage

Basic Application

from baseweb import Baseweb

app = Baseweb(__name__)

# ASGI entry point for running with uvicorn/gunicorn
asgi_app = app._asgi_app

Run with: gunicorn -k uvicorn.workers.UvicornWorker "myapp:asgi_app"

With REST API

from baseweb import Baseweb, Resource

app = Baseweb(__name__)

class MyResource(Resource):
    async def get(self):
        return {"message": "Hello, async world!"}

    async def post(self):
        data = await request.get_json()
        return {"received": data}

app.add_resource(MyResource, "/api/my-resource")

With WebSockets

from baseweb import Baseweb

app = Baseweb(__name__)

@app.socketio.on("connect")
async def handle_connect(sid, environ):
    await app.socketio.emit("connected", {"data": "Connected"})

@app.socketio.on("message")
async def handle_message(sid, data):
    # Echo back to the sender
    return {"echo": data}

With Authentication

from baseweb import Baseweb

app = Baseweb(__name__)

def authenticator(scope, request, *args, **kwargs):
    # Validate request/auth and return True/False
    return True

app.authenticator = authenticator

# Use @app.authenticated(scope) decorator for protected handlers
@app.socketio.on("private_event")
@app.authenticated("app.events.private")
async def handle_private(sid, data):
    return {"status": "authorized"}

For more examples, see the documentation.

Legacy Flask Support

For Flask-based applications (pre-0.5.0):

  1. Pin to legacy version: Use baseweb<0.5.0 for Flask/Flask-SocketIO support
  2. Migrate to Quart: Follow the Migration Guide

The baseweb-demo repository has a legacy tag pointing to the last Flask-compatible commit.

Documentation

Full documentation available at Read the Docs:

Development

Prerequisites

  • Python 3.10, 3.11, or 3.12
  • uv for dependency management

Setup

git clone https://github.com/christophevg/baseweb.git
cd baseweb
uv sync --all-extras

Testing

# Run tests
uv run pytest

# Run linting
uv run ruff check src tests

# Or use Makefile
make test      # run tests
make check     # run all checks

Multi-Version Testing

# Install all Python versions (one-time setup)
make install-pythons

# Run tests on all versions
uv run tox

Project Structure

Directory Purpose
src/baseweb/ Main package source
tests/ Test suite
docs/ Sphinx documentation

Contributing

See Contributing for guidelines.

Changelog

See CHANGELOG.md for version history. For released versions, see GitHub Releases.

License

MIT

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

baseweb-0.6.0.tar.gz (6.9 MB view details)

Uploaded Source

Built Distribution

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

baseweb-0.6.0-py3-none-any.whl (3.5 MB view details)

Uploaded Python 3

File details

Details for the file baseweb-0.6.0.tar.gz.

File metadata

  • Download URL: baseweb-0.6.0.tar.gz
  • Upload date:
  • Size: 6.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for baseweb-0.6.0.tar.gz
Algorithm Hash digest
SHA256 b77812d4bedcfc5967030612c9ab8dc0f0f37ee8c84a92d4bb6681f2f06f53e8
MD5 5f6f542a20026f503d46ba37daf87bee
BLAKE2b-256 ecbaaa0d5e69a03657058d2554a58465d6d95d08638e0709e64f79acf7e697d9

See more details on using hashes here.

File details

Details for the file baseweb-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: baseweb-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for baseweb-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d4b9e459c5e00b1b5badd302b2f799f5eb1757155704683ff14a044a325e51e
MD5 8b70b1184bebcd095b0b49ab9cae0875
BLAKE2b-256 e6ace84665bcd216749b8b12abb6cef14318bf3c2fefbaaf4a6b9fcb5e0b6bf6

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