Skip to main content

A routing library for flask applications obeying the "Decorator Design Pattern".

Project description

## Flask Compose

A simple router that promotes component driven endpoint design.

#### Installation

```bash
$ pip install flask-compose
```

#### Getting Started

Please explore the "examples" directory for more detailed samples.

`flask-compose` can be applied to any `flask` application without consideration for any existing routing libraries. `flask-compose`, at its core, is a glorified call to `Flask.add_url_rule`.

Creating a route is as simple as defining a few types:

```python
from flask import Flask
from flask_router import Component, Handler, Include, Route, Router


# Handler
class MyHandler(Handler): ...


# Components
class UserComponent(Component): ...
class SQLAlchemyComponent(Component): ...


# Controllers
def browse_type(handler, **uri_args): ...
def get_type(handler, **uri_args): ...


# Routes
route = Include(
'/users', routes=[
Route('', controller=browse_type, handler=MyHandler, components=[UserComponent]),
Route('/<id>', controller=get_type, handler=MyHandler, components=[UserComponent]),
], components=[SQLAlchemyComponent])


app = Flask(__name__)
api = Router(app)
api.add_routes([route])
```

You're done! The above code can be thought to evaluate to:

```python
# For browse type controllers.
def dispatch_request(**uri_args):
handler = SQLAlchemyComponent(UserComponent(MyHandler()))
return browse_type(handler, **uri_args)
```

#### Why

REST resources have well known behaviors that rarely deviate on a per resource basis. Knowing this, resources should lend themselves to reuse. However, as often happens in glue code, there is just enough variability between resources that reuse is either impossible or impractical. The "Decorator Design Pattern" was concieved as an attempt to address this type of problem. This library encourages its use through its routing system.

#### Philosophy

This library encourages the use of the "Decorator Design Pattern". Not to be confused with Python's decorators, the "Decorator Design Pattern" is an object-oriented approach to annotating behavior. The naming of these two concepts is not coincidental. Python's decorators describe on a function-based level what the "Decorator Design Pattern" describes on an object-based level.

#### Credits

With thanks to the molten framework, flask, and "The Gang of Four" for their contributions to the software world. Without whom this project would not have been possible.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_compose-0.2.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

flask_compose-0.2.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file flask_compose-0.2.0.tar.gz.

File metadata

  • Download URL: flask_compose-0.2.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

File hashes

Hashes for flask_compose-0.2.0.tar.gz
Algorithm Hash digest
SHA256 56a469de5c6bd9059b097ccd461e55165f19dca95c14067e51c09b1d30d6e59c
MD5 8add2d30d4d51fe87680681b9330a6e4
BLAKE2b-256 7f5366ff431ff14777a149f3955a6626e9083b4ced5d80bb549f7a2b84d905e9

See more details on using hashes here.

File details

Details for the file flask_compose-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: flask_compose-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

File hashes

Hashes for flask_compose-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a194f61a58954806d6786acc27d8f218dd3666ada12de305da6ec8369e6b2c62
MD5 7e48a8b0b35ace7248648a3db5e5c57a
BLAKE2b-256 c18ce41666e03404ccc0b7da9463c9efd677f5f99cac61b50194d8efb1bb9c73

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