Metadata-Version: 2.4
Name: abstract-flask
Version: 0.0.0.1080
Summary: A composable toolkit for standing up Flask APIs without repeating yourself.
Author-email: putkoff <partners@abstractendeavors.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/AbstractEndeavors/abstract_flask
Project-URL: Repository, https://github.com/AbstractEndeavors/abstract_flask
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: flask
Requires-Dist: flask-cors
Requires-Dist: werkzeug
Requires-Dist: abstract-essentials
Requires-Dist: abstract-apis
Requires-Dist: abstract-database>=0.0.2.208
Requires-Dist: abstract-utilities>=0.2.2.794
Provides-Extra: users
Requires-Dist: psycopg[binary]; extra == "users"
Provides-Extra: aiohttp
Requires-Dist: aiohttp; extra == "aiohttp"

# abstract-flask

Abstract Flask turns a nested dictionary of Python functions into a Flask API. The same route definitions can describe endpoints to a client, mount an application under a prefix and combine routes from several packages.

## Installation

Use the `aiohttp` extra for the optional aiohttp integration and `users` for the PostgreSQL user utilities.

```sh
python -m pip install abstract-flask
```

## Quick start

Build a route and exercise it with Flask’s in-process client.

```python
from abstract_flask import get_Flask_app, spec

def double(value):
    return {"value": 2 * value}

routes = {"math": {"double": spec(double, "POST", response="native")}}
app = get_Flask_app(name="example", routes=routes)
response = app.test_client().post("/math/double", json={"value": 4})
print(response.get_json())  # {"value": 8}
```

## Designing an API

- Nested keys form URL segments. Use a key such as `<int:item_id>` to bind a path parameter.
- A callable leaf uses the default result envelope. Use `spec` to declare HTTP methods, argument handling, status codes and native Flask responses. A list of specs can serve different methods at one path.
- `merge_categories` combines independent route trees and reports duplicate leaves. `describe_categories` returns a machine-readable catalog.
- `get_Flask_app` also accepts modules containing Flask Blueprints. Use `url_prefix` for a primary mount, `dual_prefix` for a second mount or `arms_group` to discover registered Python entry points.

## Request and response handling

Use `inputs="path"` when a view should receive only URL variables. The default `merged` mode combines request fields with URL variables, with the URL value taking precedence. A native response can return a Flask response or a `(payload, status)` tuple. This lets related endpoints share the same registration tree while keeping their individual HTTP contracts.
