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.1005.tar.gz (20.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.1005-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for abstract_flask-0.0.0.1005.tar.gz
Algorithm Hash digest
SHA256 c42d707b75caf096e23adb45f62e1c2537d93296721f65c280bf89c91730c5f7
MD5 92f777dba596ce0b748b8f005e8ba553
BLAKE2b-256 d99b9c7758dc719f6fd64daa8adea358c7f18e1b247976ac3a018fa5c0e8497c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for abstract_flask-0.0.0.1005-py3-none-any.whl
Algorithm Hash digest
SHA256 2a5db9b2d3297aac9edcfe63d6dcb1983f7f3a2f1de3ab59dd78707af6377811
MD5 d95b48ced05ee98be69b9286448ba287
BLAKE2b-256 2377e8d996c69c816a4b8e6dc4267e3ea01e9c6e84308dd201e2bb5746c2c3a4

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