Skip to main content

A modular Flask API framework with auto CRUD and migrations

Project description

Wapp Framework - Quickstart Guide

Wapp is a modular, plug-and-play framework for building Flask APIs with automatic CRUD endpoints, model registration, and Alembic migrations. This guide will help you get started as a developer using Wapp as an external package.


🚀 Getting Started: Step-by-Step

1. Install Wapp and Dependencies

Install Wapp from PyPI (or your package registry) and its dependencies:

pip install wapp flask flask_sqlalchemy alembic python-dotenv pydantic

2. Initialize Your Project

Create a new directory and initialize a basic Flask project structure:

myproject/
  app.py
  env.py
  mywapp/
    __init__.py
    wapp.py
  migrations/
  alembic.ini
  • env.py will hold your DB and environment config.
  • mywapp/wapp.py will define your first wapp.

3. Configure the Environment

In env.py:

import os
from flask_sqlalchemy import SQLAlchemy
from dotenv import load_dotenv

load_dotenv()
DATABASE_URL = os.getenv('DATABASE_URL', 'sqlite:///app.db')
db = SQLAlchemy()

Create a .env file (optional):

DATABASE_URL=sqlite:///app.db
AUTO_MIGRATE=true
ENV=development

4. Define Your First Wapp

In mywapp/wapp.py:

from env import db
from wapp import Wapp


class Foo(db.Model):
    __tablename__ = 'foo'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)

    class WappModel:
        slug = "foo"
        name = "Foo"

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


class MyWapp(Wapp):
    class Models:
        foo = Foo

    class Endpoints:
        _foo = True  # Enable auto-CRUD for Foo

5. Create the Main App

In app.py:

from flask import Flask
from env import db, DATABASE_URL
from mywapp.wapp import MyWapp
from wapp import Wapp


class MainWapp(Wapp):
    class Wapps:
        mywapp = MyWapp


def create_app():
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URL
    db.init_app(app)
    MainWapp.register_wapp(app, db)
    return app


if __name__ == '__main__':
    app = create_app()
    app.run(debug=True)

6. Set Up Alembic for Migrations

  • Initialize Alembic (if not already):
    alembic init migrations
    
  • Edit alembic.ini to set script_location = migrations and sqlalchemy.url = sqlite:///app.db (or your DB URI).
  • Edit migrations/env.py to import your models and set target_metadata = db.metadata.

IMPORTANT: To ensure Alembic autogenerate detects your models, you must import your SQLAlchemy db instance in migrations/env.py and set:

from env import db  # Use the same db instance as your app
# ...
target_metadata = db.metadata

This ensures Alembic uses the same metadata as your app and can autogenerate migrations for your models.

7. Run Migrations

  • To auto-generate and apply migrations:
    python -m wapp.migrate
    # or, if installed as a CLI:
    wapp-migrate
    

8. Run the App

export FLASK_APP=app.py
flask run

9. Test Your API

  • List Foos: GET /mywapp/foo/
  • Create Foo: POST /mywapp/foo/ (with JSON body)
  • Get Foo: GET /mywapp/foo/<id>
  • Update Foo: PUT /mywapp/foo/<id>
  • Delete Foo: DELETE /mywapp/foo/<id>

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.0.0.tar.gz (6.6 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.0.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: saitech_wapp-0.0.0.tar.gz
  • Upload date:
  • Size: 6.6 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.0.0.tar.gz
Algorithm Hash digest
SHA256 8d2cca7e715b0c9f6d38580b257664e373b9c7547e0d07cc99850848fa7c55fb
MD5 be2323b0bbf0804c898e4b51390fa7c7
BLAKE2b-256 b56c20775277732e48cf218aaf8e3b8b3ef26c2a0f4eaecf0283b2dc9066e897

See more details on using hashes here.

Provenance

The following attestation bundles were made for saitech_wapp-0.0.0.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.0.0-py3-none-any.whl.

File metadata

  • Download URL: saitech_wapp-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 455e76ad42012b9078b1566965e3e072b6dc8392f790a1df81aad12e912b82f8
MD5 f693b347b1692ab7d0391256440b1fbb
BLAKE2b-256 5fb2f61d3338c1d28b50db11bea91c5823f97a5f629ef4247bf1b1c1c9a959d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for saitech_wapp-0.0.0-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