Skip to main content

A modular Flask API framework with auto CRUD and migrations

Project description

Wapp — Quickstart Guide

Wapp is a modular framework for building Flask APIs with automatic CRUD endpoints, nested applications, and Alembic migrations. This guide will help you quickly set up your project, define your models and endpoints, and customize request and response types.


Quick Setup Guide

TL;DR

mkdir my_project && cd my_project
pip install saitech-wapp
wapp-init
python app.py

Your API docs will be available at: http://127.0.0.1:5000/apidocs/


Prerequisites

  • Python 3.8+ (Wapp and its dependencies require at least Python 3.8).
  • Install the package using your preferred tool:
pip install saitech-wapp

Or with Poetry/PDM/UV:

poetry add saitech-wapp
# or
pdm add saitech-wapp
# or
uv add saitech-wapp

Bootstrap Your Project

Use the CLI to initialize a new Wapp project:

wapp-init

This command will create necessary files like app.py, app_env.py, migrate_app.py, and create_app.py.

(If you installed in editable mode, you can also run python -m cli.)


Running the Application

Start your application:

python app.py

Open the API docs at: http://127.0.0.1:5000/apidocs/


Database Migrations

Initialize the database with Alembic:

alembic revision --autogenerate -m "init"
alembic upgrade head

Composing Blocks: How It Works

1. Flask

Flask provides the basic structure for routing, request/response management, and middleware.

2. SQLAlchemy

SQLAlchemy abstracts database interactions via ORM models.

3. Wapp

Wapp builds on Flask and SQLAlchemy, adding:

  • Automatic CRUD endpoint generation
  • Nested applications for grouping related functionality
  • Integration with Alembic migrations

Defining Models

Define models by extending db.Model from SQLAlchemy:

from app_env import db

class YourModel(db.Model):
    __tablename__ = 'your_model'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(120), nullable=False)

    class WappModel:
        slug = "your_model"
        name = "Your Model"

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}

Example: User Model

class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)

    class WappModel:
        slug = "user"
        name = "User"

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}

Defining Endpoints

Endpoints are classes that handle API requests for your models. You can let Wapp auto-generate CRUD endpoints or define custom ones.

Creating a Custom Endpoint

from wapp.core import Wapp
from wapp.endpoint_base import WappEndpoint
from pydantic import BaseModel as PydanticModel

class YourRequestModel(PydanticModel):
    name: str

class YourResponseModel(PydanticModel):
    id: int
    name: str

class YourEndpoint(WappEndpoint):
    """ Get your model by ID
    ---
    tags: [Your Model]
    responses:
      200:
        description: Successful retrieval
    """
    class Meta:
        method = 'GET'
        pattern = '/your_model/<int:id>'
        name = 'Get YourModel'
        request_model = YourRequestModel
        response_model = YourResponseModel

    def handle(self, request, query, path, body):
        obj = YourModel.query.get(path['id'])
        if not obj:
            return {"error": "Not Found"}, 404
        return obj.as_dict()

Using Auto-CRUD Generation

If your endpoint class includes _model = True, Wapp generates CRUD endpoints automatically.

Example: UsersWapp with Auto-CRUD + Custom Endpoint

class UsersWapp(Wapp):
    class Models:
        user = User

    class Endpoints:
        _user = True  # Auto-CRUD for User

        class UsersStatsEndpoint(WappEndpoint):
            """ Retrieve user statistics
            ---
            tags: [User Stats]
            responses:
              200:
                description: User statistics
            """
            class Meta:
                method = 'GET'
                pattern = '/stats'
                name = 'User Stats'

            def handle(self, request, query, path, body):
                total_users = User.query.count()
                return {"total_users": total_users}

        stats = UsersStatsEndpoint

Request and Response Types

Define request/response bodies with Pydantic models for validation and documentation.

class CreateUserRequest(PydanticModel):
    username: str
    email: str

class CreateUserResponse(PydanticModel):
    id: int
    username: str
    email: str

Attach them in your endpoint Meta:

class CreateUserEndpoint(WappEndpoint):
    """ Create a new user
    ---
    tags: [User]
    """
    class Meta:
        method = 'POST'
        pattern = '/user'
        name = 'Create User'
        request_model = CreateUserRequest
        response_model = CreateUserResponse

    def handle(self, request, query, path, body):
        new_user = User(username=body.username, email=body.email)
        db.session.add(new_user)
        db.session.commit()
        return new_user.as_dict(), 201

Conclusion

With Wapp, you can rapidly build robust Flask APIs with SQLAlchemy models, Alembic migrations, and auto-generated CRUD.

  • Initialize with wapp-init
  • Define models via SQLAlchemy
  • Expose them with auto-CRUD or custom endpoints
  • Use Pydantic for validation and response typing

For advanced usage (nested apps, migrations, customization), see the full documentation and included examples.

Happy coding 🚀

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

saitech_wapp-0.2.5.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

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

saitech_wapp-0.2.5-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file saitech_wapp-0.2.5.tar.gz.

File metadata

  • Download URL: saitech_wapp-0.2.5.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for saitech_wapp-0.2.5.tar.gz
Algorithm Hash digest
SHA256 8b72c035fc88f00b7a86d79195fb32b7a9f03cc525d8f4a4aed39a0693edd3cb
MD5 0f6b90c6af9b1856575aa4fe96932c7e
BLAKE2b-256 964d1f7cee6af29c470417bda347d82645b5631772459ecf63ecf690d3b25eeb

See more details on using hashes here.

Provenance

The following attestation bundles were made for saitech_wapp-0.2.5.tar.gz:

Publisher: python-publish.yml on saitech-org/wapp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file saitech_wapp-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: saitech_wapp-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for saitech_wapp-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ec28b0a467e6e5818da775e1a3e11b64e2f668a0e6c4c5537f678ab265684940
MD5 b4329ab6056c0eb5e52d573a8fc3d407
BLAKE2b-256 fdaed33d94fb2881cd81e4ca74c0183b1493eff897db374b7215a62c271a78fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for saitech_wapp-0.2.5-py3-none-any.whl:

Publisher: python-publish.yml on saitech-org/wapp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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