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.1006.tar.gz (20.4 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.1006-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: abstract_flask-0.0.0.1006.tar.gz
  • Upload date:
  • Size: 20.4 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.1006.tar.gz
Algorithm Hash digest
SHA256 a37ff2c8b258648e63076d69907e761d32117188a5a2812666a60c6b1b49ddb5
MD5 498be532376152e64ad5e9cb280f9a07
BLAKE2b-256 8fd6d3d8811004421c2ff431a33162781826bac4b36cde6b34db7690c1e4957c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for abstract_flask-0.0.0.1006-py3-none-any.whl
Algorithm Hash digest
SHA256 cc08824a9ed07891e979aab02a7e6d33300c271d6f8e9308af2f2e09839bd89d
MD5 e1ea112cc0590937a5f774bbc4485df3
BLAKE2b-256 fc137149e2d4292585d7caa991f7cf1e84f0b618719465ba6dcc9d44b51f1139

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