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.4.tar.gz (9.1 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.4-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: saitech_wapp-0.1.4.tar.gz
  • Upload date:
  • Size: 9.1 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.4.tar.gz
Algorithm Hash digest
SHA256 711d44c177bebb20c026627b5b780c9e342960c622e8623bdcb8e67ec45ab9c3
MD5 71d0e9400b4e759a3db35b4a739bb442
BLAKE2b-256 a0b7f5ccc7e596946f37e4827c29a8b57e8a7d24182f59d914a541641153a57b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: saitech_wapp-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 7.3 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d17ef7d31d5a71c28ec131c57f167ae5545d4be51ac4542ee0bf123de66876c8
MD5 3275b054a3ed611ddc4a287ddc48e3e9
BLAKE2b-256 532a6bc41298307aead25139b52fece00c4d2f954993e1325f379b5738d3a187

See more details on using hashes here.

Provenance

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