Skip to content

A lightweight and modern Python web framework designed for speed, simplicity, and a great developer experience.

License

Notifications You must be signed in to change notification settings

Jsweb-Tech/jsweb

Repository files navigation

JsWeb Logo

PyPI version License PyPI version

Discord Documentation Sponsor GitHub PayPal Sponsor

JsWeb: The Blazing-Fast ASGI Lightweight Python Web Framework

JsWeb is a modern, high-performance Python web framework built from the ground up on the ASGI standard. It's designed for developers who want the speed of asynchronous programming with the simplicity of a classic framework.

With built-in, zero-configuration AJAX and a focus on developer experience, JsWeb makes it easy to build fast, dynamic web applications without writing a single line of JavaScript.

Core Features

  • Blazing-Fast ASGI Core: Built for speed and concurrency, compatible with servers like Uvicorn.
  • Automatic AJAX: Forms and navigation are automatically handled in the background for a smooth, single-page-application feel with zero configuration.
  • Elegant Routing: Define routes with a simple decorator syntax.
  • Jinja2 Templating: Render dynamic HTML with a powerful and familiar templating engine.
  • Built-in Security: Comes with CSRF protection, password hashing, and cache-control tools out of the box.
  • Full-Featured Forms: A powerful, easy-to-use form library with validation.
  • SQLAlchemy Integration: Includes Alembic for easy database migrations.
  • Automatic Admin Panel: A production-ready admin interface for your models that's generated automatically.
  • Modular Blueprints: Organize your code into clean, reusable components.
  • Powerful CLI: A command-line interface for creating projects, running the server, and managing your database.

Contributors

Command-Line Interface (CLI)

JsWeb comes with a powerful set of command-line tools to streamline your development workflow.

  • jsweb run: Starts the development server.

    • --host <address>: Specify the host to run on (e.g., 0.0.0.0).
    • --port <number>: Specify the port.
    • --reload: Enable auto-reloading on code changes.
    • --qr: Display a QR code for accessing the server on your local network.
  • jsweb new <project_name>: Creates a new, production-ready JsWeb project with a clean directory structure and all necessary files.

  • jsweb db ...: A group of commands for managing your database migrations with Alembic.

    • jsweb db prepare -m "Your message": Generates a new database migration script based on changes to your models.
    • jsweb db upgrade: Applies all pending migrations to the database.
    • jsweb db downgrade: Reverts the last applied migration.
  • jsweb create-admin: An interactive command to create a new administrator user in the database.

Installation & Setup

Get up and running in under a minute.

  1. Install JsWeb:

    pip install jsweb
  2. Create a new project:

    jsweb new my_project
    cd my_project
  3. (Optional) Set up the database:

    jsweb db prepare -m "Initial migration"
    jsweb db upgrade
  4. Run the development server:

    jsweb run --reload

Your new JsWeb project is now running with auto-reloading enabled!

Quickstart: A Real-World Example

Here’s how a simple but structured JsWeb application looks, using Blueprints to organize your code.

views.py

from jsweb import Blueprint, render

# 1. Create a "Blueprint" for a group of related pages.
views_bp = Blueprint('views')

# 2. Define a route on the blueprint.
@views_bp.route("/")
async def home(req):
    # The render function automatically finds your templates.
    return render(req, "welcome.html", {"user_name": "Guest"})

app.py

from jsweb import JsWebApp
import config

# Import the blueprint you just created.
from views import views_bp

# 3. Create the main application instance.
app = JsWebApp(config=config)

# 4. Register your blueprint with the app.
app.register_blueprint(views_bp)

# The `jsweb run` command will find and run this `app` instance.

This structure allows you to organize your application into logical components, making it clean and scalable from the very beginning.

For more detailed usage, refer to the official documentation, individual module docstrings, and examples within the codebase.