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.1.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.5.1-py3-none-any.whl (3.5 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: baseweb-0.5.1.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.5.1.tar.gz
Algorithm Hash digest
SHA256 dba84806a7e6fb9156071954f1bab82fa17dc34087e68af5be41931843f18bac
MD5 4ec5200fb650b66e24e550b401c463fd
BLAKE2b-256 cb0a68cc4602e59373bc9c769122acab6bc80ad9af7d0f4119285dd9be0168c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: baseweb-0.5.1-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.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f0d260bf59bbcedb747d1a8ea8c8806a32c85d2a1e29840d2b4479d0acf0e4bf
MD5 5146d9a5234b2b29f75a0059457ec8e0
BLAKE2b-256 7c497f39ba01150705e541dd3e92ab7a498fd352409e1d12ca8943da2af6d11f

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