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.5.0.tar.gz (7.0 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.5.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for baseweb-0.5.0.tar.gz
Algorithm Hash digest
SHA256 04ce7168c379aa1abc918aacf3fad76f07aebb04d944f2bf5efddfb19f089e4a
MD5 057b72ae4f2bb3d081d4de5c0957be5f
BLAKE2b-256 026b176934d4af3fc6d96581a30bc153e6956c217468623a043041f74e92934c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for baseweb-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d2e2cdc7e0337deee25673a1011c671d46579e40faf791f55d5b9a8994e8b16d
MD5 e91ee5fad3bf69d3fde5a19ae57e804e
BLAKE2b-256 7009240d1b53e74c0c6f7a5fadd69c99a91f87e622bd918bcb7423b35a34a6bf

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