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

Uploaded Python 3

File details

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

File metadata

  • Download URL: baseweb-0.5.2.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.2.tar.gz
Algorithm Hash digest
SHA256 87615aa9ef346753c5b03c3f064297d093588bbd05933fb8456198c0efc069d4
MD5 2d0d181a1e9b7595f1dd2a9bec7dbacd
BLAKE2b-256 c8cc3b0c57864394eb082e04358c6da0e1f9f89df0d9539a37bc956b64956ed6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: baseweb-0.5.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5206fce78af6c1db55499b5192a84679c1f8eedb56ecb8953ef82f67d30e35a9
MD5 24e0720905277ff9fb60528bcc63628a
BLAKE2b-256 6fa041997a549ce9d826cc59e8fbb1e41de341a831aab30fde8901cab2c489e4

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