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.pywill hold your DB and environment config.mywapp/wapp.pywill 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.inito setscript_location = migrationsandsqlalchemy.url = sqlite:///app.db(or your DB URI). - Edit
migrations/env.pyto import your models and settarget_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d2cca7e715b0c9f6d38580b257664e373b9c7547e0d07cc99850848fa7c55fb
|
|
| MD5 |
be2323b0bbf0804c898e4b51390fa7c7
|
|
| BLAKE2b-256 |
b56c20775277732e48cf218aaf8e3b8b3ef26c2a0f4eaecf0283b2dc9066e897
|
Provenance
The following attestation bundles were made for saitech_wapp-0.0.0.tar.gz:
Publisher:
python-publish.yml on saitech-org/wapp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
saitech_wapp-0.0.0.tar.gz -
Subject digest:
8d2cca7e715b0c9f6d38580b257664e373b9c7547e0d07cc99850848fa7c55fb - Sigstore transparency entry: 511535335
- Sigstore integration time:
-
Permalink:
saitech-org/wapp@d9dd584da1259a2a1d6fedd4efa71506a29d1d01 -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/saitech-org
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d9dd584da1259a2a1d6fedd4efa71506a29d1d01 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
455e76ad42012b9078b1566965e3e072b6dc8392f790a1df81aad12e912b82f8
|
|
| MD5 |
f693b347b1692ab7d0391256440b1fbb
|
|
| BLAKE2b-256 |
5fb2f61d3338c1d28b50db11bea91c5823f97a5f629ef4247bf1b1c1c9a959d1
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
saitech_wapp-0.0.0-py3-none-any.whl -
Subject digest:
455e76ad42012b9078b1566965e3e072b6dc8392f790a1df81aad12e912b82f8 - Sigstore transparency entry: 511535336
- Sigstore integration time:
-
Permalink:
saitech-org/wapp@d9dd584da1259a2a1d6fedd4efa71506a29d1d01 -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/saitech-org
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d9dd584da1259a2a1d6fedd4efa71506a29d1d01 -
Trigger Event:
release
-
Statement type: