Skip to main content

A composable toolkit for standing up Flask APIs without repeating yourself. Handles blueprint discovery, CORS, request parsing, endpoint introspection, and route generation — so the only code you write is the code that matters.

Project description

abstract_flask

A composable toolkit for standing up Flask APIs without repeating yourself. Handles blueprint discovery, CORS, request parsing, endpoint introspection, and route generation — so the only code you write is the code that matters.

Install

pip install abstract_flask

Quickstart

# my_api/__init__.py
from . import routes
from abstract_flask import get_Flask_app

app = get_Flask_app(routes=routes, allowed_origins=["https://yourdomain.com"])

That's it. Blueprints are discovered from any *_bp objects in your routes module, CORS is applied, and introspection endpoints are registered automatically.

Full signature

app = get_Flask_app(
    name="my_api",              # Flask app name (default: caller's __name__)
    routes=routes,              # module to scan for *_bp Blueprints
    bp_list=None,               # or pass blueprints explicitly
    url_prefix="v1",            # prefix for blueprint registration + filtered /endpoints
    allowed_origins=["https://example.com"],
    supports_credentials=True,
)

Running

from abstract_flask import main_flask_start

main_flask_start(app, key_head="MYAPI", env_path=".env")
# reads MYAPI_DEBUG, MYAPI_HOST, MYAPI_PORT from env

Package structure

abstract_flask/
├── abstract_flask.py        # App factory, CORS, audit logging, introspection
├── request_utils/
│   ├── request_utils.py     # get_request_data, extract_request_data
│   ├── get_requests.py      # required_keys, execute_request, get_spec_kwargs
│   └── parse_utils.py       # parse_request, parse_and_spec_vars
├── network_utils/
│   └── ip_utils.py          # get_host_ip, get_user_ip, get_ip_addr
├── user_utils/
│   └── user_utils.py        # get_user_name (from request or fallback)
└── generator/
    ├── generateFlaskRoute.py # Auto-generate Flask routes from Python files
    └── help_utils.py         # ?help introspection for any endpoint

Core modules

App factory (abstract_flask.py)

Function Purpose
get_Flask_app(...) One-call app factory: blueprints, CORS, logging, introspection
get_bp(name, abs_path) Create a named Blueprint with a logger
main_flask_start(app) Run the app using env-driven host/port/debug

Every app gets these endpoints for free:

  • GET /endpoints — all registered routes
  • GET /<prefix>/endpoints — routes under that prefix
  • GET /prefixes — unique top-level route segments

Request utilities (request_utils/)

from abstract_flask.request_utils import get_request_data, required_keys, parse_request
  • get_request_data(req) — Returns a dict from JSON body, form data, or query string (checked in that order).
  • extract_request_data(req, res_type) — Full extraction: user, IP, headers, cookies, files, metadata. Pass res_type to narrow scope.
  • required_keys(keys, req, defaults) — Validate that required keys are present; returns the data dict or a 400 error payload.
  • parse_request(req) — Split a request into positional args and kwargs.
  • get_spec_kwargs(var_types, args, **kwargs) — Type-coerced argument extraction against a schema.

Route generator (generator/)

Auto-generate Flask endpoints from plain Python files:

from abstract_flask.generator import generate_from_files

source = generate_from_files(
    directory="./my_functions",
    bp_name="auto_bp",
    url_prefix="generated",
)

Every public function becomes a GET/POST endpoint. Async functions are preserved. Pass ?help to any generated endpoint to get parameter introspection via offer_help.

Register routes programmatically against an existing blueprint:

from abstract_flask.generator import register_category

register_category(bp, "math", {
    "add": lambda a, b: a + b,
    "multiply": lambda a, b: a * b,
})
# creates /math/add, /math/multiply

Network utilities (network_utils/)

from abstract_flask.network_utils import get_host_ip, get_user_ip

User utilities (user_utils/)

from abstract_flask.user_utils import get_user_name

Resolves username from the request's .user attribute, falling back to IP-based lookup via UserIPManager.

Dependencies

  • flask, flask_cors, werkzeug
  • abstract_utilities, abstract_security, abstract_queries

License

MIT

Author

putkoffpartners@abstractendeavors.com

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

abstract_flask-0.0.0.1018.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

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

abstract_flask-0.0.0.1018-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file abstract_flask-0.0.0.1018.tar.gz.

File metadata

  • Download URL: abstract_flask-0.0.0.1018.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for abstract_flask-0.0.0.1018.tar.gz
Algorithm Hash digest
SHA256 4bd20263939eee065d7fc7e0fbcf7180b49e1db5be51a7904bca6ebb8a4a0b1a
MD5 571af468fa60cbd235575875429b1b13
BLAKE2b-256 a3b7a827e5b824f6350067a4254e7cb96b27a2efbf5c435400a96a2a3cfb651a

See more details on using hashes here.

File details

Details for the file abstract_flask-0.0.0.1018-py3-none-any.whl.

File metadata

File hashes

Hashes for abstract_flask-0.0.0.1018-py3-none-any.whl
Algorithm Hash digest
SHA256 6887c064ad8306bc1770f24975cae9c72761249ee611735a36b2e7f27d7a33c1
MD5 68b9d331977e12575bd34ce66951c976
BLAKE2b-256 e55fb34572c248b3b8cb902a40d97c528ab6e31dfb6bad092830f3e3432746e1

See more details on using hashes here.

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