Skip to main content

A lightweight Python framework for building and managing web applications.

Project description

Pyweber Framework

Pyweber Logo

PyPI version Coverage Status License

Pyweber is a lightweight Python web framework designed to create dynamic, reactive web applications with a simple and intuitive API. It combines the simplicity of Python with the reactivity of modern frontend frameworks.

Key Features

  • Reactive Templates: Create dynamic UIs that automatically update when data changes
  • Component-Based Architecture: Build reusable components for consistent interfaces
  • Integrated Hot Reload: See changes instantly during development
  • Intuitive DOM Manipulation: Query and modify elements with familiar selectors
  • Event-Driven Programming: Handle user interactions with Python event handlers
  • WebSocket Integration: Real-time communication between client and server
  • Minimal Configuration: Get started quickly with sensible defaults

Quick Start

Installation

pip install pyweber

Create a Project

# Create a new project with configuration
pyweber create-new my_app --with-config
cd my_app

Build a Simple Counter

import pyweber as pw

class Main(pw.Element):
    def __init__(self):
        super().__init__(tag='div', classes=['counter'])
        self.childs = [
            pw.Element('h1', content='Pyweber Counter'),
            pw.Element(
                tag='p',
                content='Count:',
                childs=[
                    pw.Element('span', id='count', content=0)
                ]
            ),
            pw.Element(
                'button',
                id='increment',
                content='Increment',
                events=pw.TemplateEvents(onclick=self.increment)
            )
        ]
    
    async def increment(self, e: pw.EventHandler):
        self.count = e.template.querySelector("#count")
        current = int(self.count.content)
        self.count.content = str(current + 1)
        self.create_element()
        e.update()
    
    def create_element(self):
        self.count.parent.parent.add_child(
            pw.Element(
                tag='p',
                content=self.count.content
            )
        )

class Counter(pw.Template):
    def __init__(self):
        super().__init__(template='', title='Hello pyweber')
        self.body.childs = [Main()]

app = pw.Pyweber()

@app.route('/')
def home():
    return Counter()

if __name__ == "__main__":
    pw.run(route='/')

Run your application:

pyweber run --reload

Core Components

Pyweber

The main application class that handles routing, middleware, and template management:

app = pw.Pyweber()

@app.route('/')
def home():
    return HomePage()

@app.route('/users/{user_id}')
def user_profile(user_id: int):
    return UserProfile(user_id=user_id)

Template

Templates represent pages or components with HTML structure and Python logic:

class HomePage(pw.Template):
    def __init__(self, app: pw.Pyweber):
        super().__init__(template="index.html")
        self.title = self.querySelector("h1")
        self.title.content = "Welcome to PyWeber!"

Element

Elements represent DOM nodes that you can manipulate:

# Create elements
button = pw.Element(tag="button", content="Click me", id="my-button")

# Modify properties
button.content = "Clicked!"
button.attrs["disabled"] = "true"
button.style["color"] = "red"
button.add_class("active")

Events

Handle user interactions with Python functions:

# Define event handlers
async def handle_click(e: pw.EventHandler):
    e.element.content = "Processing..."
    e.update()

    await process_data()
    e.element.content = "Done!"
    e.update()

# Attach events
button.events.onclick = handle_click

Window

Interact with the browser window:

# Access window properties
width = template.window.inner_width
scroll_pos = template.window.scroll_y

# Register window events
template.window.events.onresize = handle_resize
template.window.events.onscroll = handle_scroll

Comparison with Other Frameworks

Feature PyWeber Flask Django React
Learning Curve Low Low High High
Reactivity Built-in Manual Manual Built-in
DOM Manipulation Python API JavaScript JavaScript JSX
Hot Reload Built-in Add-on Add-on Built-in
Template Language Python + HTML Jinja2 DTL JSX
Server-Side Yes Yes Yes No (by default)
Configuration Simple TOML Environment vars settings.py package.json
CLI Tools Comprehensive Limited Extensive Extensive

Configuration

PyWeber provides a flexible configuration system:

# Access configuration
from pyweber.config.config import config

# Get values
port = config.get("server", "port")
debug = config.get("app", "debug")

# Set values
config.set("server", "port", 9000)

Create or edit configuration files:

# Create config file
pyweber create-config-file

# Edit interactively
pyweber --edit

CLI Tools

PyWeber includes a powerful CLI:

# Create projects
pyweber create-new my_project

# Run applications
pyweber run --reload

# Manage configuration
pyweber add-section --section-name database

# Update framework
pyweber --update

Visit Pyweber Docs for complete documentation.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyweber-1.2.0.dev20260412.tar.gz (507.4 kB view details)

Uploaded Source

Built Distribution

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

pyweber-1.2.0.dev20260412-py3-none-any.whl (516.9 kB view details)

Uploaded Python 3

File details

Details for the file pyweber-1.2.0.dev20260412.tar.gz.

File metadata

  • Download URL: pyweber-1.2.0.dev20260412.tar.gz
  • Upload date:
  • Size: 507.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pyweber-1.2.0.dev20260412.tar.gz
Algorithm Hash digest
SHA256 3e889a1f9fc3267f8e2161c71edf56606e1a5f44f1a4f5bee4f876d36f831d25
MD5 2a235dffb62904389bc8a29a7575e145
BLAKE2b-256 6ab3a95be62a57c61ef68b75ec466f090810266e1aabc9534deb439c9c178276

See more details on using hashes here.

File details

Details for the file pyweber-1.2.0.dev20260412-py3-none-any.whl.

File metadata

File hashes

Hashes for pyweber-1.2.0.dev20260412-py3-none-any.whl
Algorithm Hash digest
SHA256 33f19bec937f1184850e382a877502c27096fd5981da41a25d87afa408381f5e
MD5 fbd8fc73d0181a8c4eaa0d6572a6efe6
BLAKE2b-256 fbd1af97d9acefee035476f2e294ec0e94fe507fa7060b32973d4bee69dfbad9

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