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

1. Install Wapp and Dependencies

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

pip install saitech-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.1.5.tar.gz (9.5 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.1.5-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: saitech_wapp-0.1.5.tar.gz
  • Upload date:
  • Size: 9.5 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.1.5.tar.gz
Algorithm Hash digest
SHA256 6a2882cb61d9c309a7d8b94935eed47efdfb7221df6bd625814c146005fcf042
MD5 4ce8e20e6b926674d51c9d6148c7c0cc
BLAKE2b-256 ae0c57afb565a999235bde28aa659a210a8e89b77f01b4bffc72e93c91b3e6f3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: saitech_wapp-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.0 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.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3539effd3dc332528a7e77744a2936886dfb7a977346b15a753f57ccc7d0fa39
MD5 1d4f30d3fdad0be253700897d1b45f4d
BLAKE2b-256 01606d64dc6ac111693b88ec2c6f6f0e1ff592288baa7ff8a300b2bd361068f0

See more details on using hashes here.

Provenance

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