Skip to main content

Utilities for building Flask apps faster: structured request parsing, safe argument extraction, user/IP introspection, logging helpers, and light-weight file/directory utilities — all packaged as small, composable modules.

Project description


Abstract Flask

PyPI version License: MIT Python Versions

Utilities for building Flask apps faster: structured request parsing, safe argument extraction, user/IP introspection, logging helpers, and light-weight file/directory utilities — all packaged as small, composable modules.

Version: 0.0.0.23
Status: Alpha
License: MIT
Author: putkoff · partners@abstractendeavors.com
Repository: github.com/AbstractEndeavors/abstract_flask


Why Abstract Flask?

Most Flask projects re-implement the same glue: normalize request data (query/form/JSON), validate keys, coerce types, find the caller’s user or IP, wire in basic logging, and juggle upload/download/process folders.

Abstract Flask provides these as small, composable utilities you can import as needed — without forcing a project layout or framework.


✨ Features

  • Robust request parsing

    • Unified access to JSON, form, and query data.
    • Required key validation and case-insensitive matching.
    • Convert positional args into typed kwargs with defaults.
  • Execution helpers

    • Run a function with validated request data and return consistent {result|error, status_code} envelopes.
  • User/IP introspection

    • Get authenticated user or resolve user by IP.
    • Extract complete request metadata (headers, cookies, files, etc.).
  • Blueprint & app tooling

    • App factory with built-in request logging.
    • /api/endpoints route for quick endpoint discovery.
  • File & directory helpers

    • Manage uploads, downloads, conversions, and user-specific directories with singleton managers.
    • Validate file extensions and safely move/copy files.
  • Network helpers

    • Discover host IP with safe fallback to 127.0.0.1.

📦 Installation

pip install abstract_flask

Dependencies

Core requirements:

  • flask
  • flask_cors
  • werkzeug
  • abstract_utilities
  • abstract_pandas

Optional integrations:

  • abstract_queries — for user/IP resolution.
  • abstract_security — for environment-driven config (main_flask_start).

🚀 Quickstart

from abstract_flask.abstract_flask import get_Flask_app, get_bp
from abstract_flask.request_utils.request_utils import extract_request_data
from flask import jsonify

# 1) Create a Blueprint
bp, _logger = get_bp(name="example")

@bp.route("/hello", methods=["GET", "POST"])
def hello():
    data = extract_request_data(request)
    return jsonify({"message": "hi", "data": data}), 200

# 2) Create the app and register Blueprints
app = get_Flask_app(name="demo_app", bp_list=[bp])

if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=5000)

📚 Core Modules

Request utilities (abstract_flask.request_utils)

  • extract_request_data(req, res_type='all')
  • get_request_info(req, res_type='user'|'ip_addr')
  • get_request_data(req)
  • required_keys(keys, req, defaults=None)
  • get_only_kwargs(varList, *args, **kwargs)
  • get_proper_kwargs(strings, **kwargs)
  • get_spec_kwargs(var_types, args=None, **kwargs)
  • execute_request(keys, req, func, desired_keys=None, defaults=None)

App helpers (abstract_flask.abstract_flask)

  • get_bp(name, abs_path=None)(Blueprint, logger)
  • addHandler(app, name=None) → app with audit logging
  • get_Flask_app(name, bp_list=None, **kwargs) → ready-to-run Flask app
  • jsonify_it(obj)(jsonify(obj), status_code)
  • /api/endpoints → discover routes

File utilities (abstract_flask.file_utils)

  • fileManager (singleton, allowed extensions)
  • AbsManager & AbsManagerDynamic (directory management)
  • Helpers for uploads, downloads, conversions, per-user dirs.

Network utilities (abstract_flask.network_utils)

  • Safe host IP detection with fallback.

🧪 Examples

Validate keys & execute a function

from abstract_flask.request_utils.get_requests import execute_request

def add(a: int, b: int) -> int:
    return a + b

@app.route("/add", methods=["GET", "POST"])
def add_endpoint():
    result = execute_request(
        keys=["a", "b"],
        req=request,
        func=add,
        desired_keys=["a", "b"],
        defaults={"a": 0, "b": 0}
    )
    return jsonify(result), result.get("status_code", 200)

Typed arg shaping with defaults

from abstract_flask.request_utils.get_requests import get_spec_kwargs

spec = {
  "query": {"value": "",   "type": str},
  "limit": {"value": 25,   "type": int},
  "exact": {"value": False,"type": bool},
}

@app.route("/search", methods=["POST"])
def search():
    data = request.get_json(silent=True) or {}
    shaped = get_spec_kwargs(spec, [], **data)
    return jsonify(shaped)

⚠️ Known Quirks

  • main_flask_start has typos (iteems, KEY_VALUS, default PORT=True). Fix before production.
  • Docstring of get_Flask_app says “Quart” but it’s Flask.
  • get_request_data is defined twice in request_utils.py; use the second implementation.
  • Optional features rely on abstract_queries and abstract_security.

🔧 Compatibility

  • Python: ≥ 3.6 (tested up to 3.11)
  • Flask: Any modern 2.x release

🤝 Contributing

Contributions welcome!

  1. Fork the repo.
  2. Create a branch (feat/your-feature).
  3. Add tests/examples.
  4. Open a pull request.

Issues and PRs are tracked on GitHub: AbstractEndeavors/abstract_flask.


📄 License

MIT © Abstract Endeavors / putkoff


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.1017.tar.gz (21.1 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.1017-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: abstract_flask-0.0.0.1017.tar.gz
  • Upload date:
  • Size: 21.1 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.1017.tar.gz
Algorithm Hash digest
SHA256 5623713caeff9e640ec4c46d5b7aecac7d2dcc528e576e931450dcdd258ddd83
MD5 633df6e89bc412a961ff41a162d6efa6
BLAKE2b-256 cb2ffe1fdf8f12ed09ae7630a2e41d3dc6c07a66ca9da1b137a31922e5c0f3ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for abstract_flask-0.0.0.1017-py3-none-any.whl
Algorithm Hash digest
SHA256 1a83fce3aee7b97ab45d0a80304b4617100857034fdd043d8bf4491bde1bad2a
MD5 513fa9584437df7d03002df17edc936a
BLAKE2b-256 41ede0b47e46366046749a545aaa37a6852d42d4d54082572440263148088482

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