Specify APIs with a Python dict and run with one line
Project description
🙈 Dead Simple Web Framework 🙉
Overview:
A dead simple framework for web applications:
Backend:
- Flask [Framework]
- MongoDB [Database]
- Redis [Cache]
- Celery + RabbitMQ [Async Tasks]
Installing:
$ pip install dead-simple-framework
Configuration:
TODO - DOCS
Example Application (demo.py
):
* Celery must be running *
$ celery -A demo worker -l info
from dead_simple_framework import Application, Task_Manager, Database, API, Route, Task
from random import choice
WEBSITES =[
"http://www.google.com",
"http://www.yahoo.com",
"http://www.ebay.com",
"http://www.cnn.com",
"http://www.pbs.org",
"https://www.reddit.com/",
]
def get_websites(n):
_websites = [*WEBSITES]
res = []
for x in range(n):
res.append(choice(_websites))
_websites.remove(res[-1])
return res
sample_config = {
'routes': {
'insert': Route( # A route with automatic CRUD support
url='/insert',
methods=['GET', 'POST', 'DELETE', 'PUT'],
collection='insert',
),
'demo': { # Another route with automatic CRUD support
'name': 'demo',
'methods': ['GET', 'POST', 'DELETE', 'PUT'],
'defaults': None,
'logic': None,
'collection': 'demo'
},
'/api/refresh': { # Route that runs an async task (API call)
'name': 'call',
'methods': ['GET'],
'defaults': None,
'logic': lambda: str(Task_Manager.run_task('scheduled_call')),
},
'/': { # Route that fetches the last result of an async task (API call)
'name': 'call_cached',
'methods': ['GET'],
'defaults': None,
'logic': lambda: str(Task_Manager.get_result('scheduled_call'))
},
'/add': { # Route that fetches the last result of an async task (API call)
'name': 'add',
'methods': ['GET'],
'defaults': None,
'logic': lambda: str(Task_Manager.run_task('add'))
},
},
'tasks': { # Async tasks available to the Task_Manager [celery] to schedule or run
'add': { # Simple Addition Task (with default arguments)
'logic': lambda x,y: x + y,
'schedule': None,
'default_args': (2,2)
},
'insert': { # Periodic Database Insert Task
'logic': lambda res: Database(collection='insert').connect().insert_one({'test': 'doc', 'result': res}),
'schedule': {}, # Default - every minute
'depends_on': 'add' # Return value substituted for `res`
},
'call_api': { # API Call Task
'logic': lambda url, params=None: str(API.get(url, params, ignore_errors=False, retry_ms=10000, num_retries=20).content),
},
'scheduled_call': Task( # Make 3 parallel API calls
name='scheduled_call',
logic=lambda: Task_Manager.parallelize([['call_api', [x]] for x in get_websites(3)]),
schedule={}
)
}
}
app = Application(sample_config)
if __name__ == '__main__':
app.run()
-
Starts a local server at http://0.0.0.0:5000/
-
Serves CRUD operations for MongoDB collection
demo
at endpoint/demo
-
Runs an asynchronous chained value calculation and insert into the
insert
collection (viewable at/insert
) -
Runs asynchronous parallel API calls and displays the latest result at endpoint
/
(can be manually run at/api/refresh
)
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
Built Distribution
Close
Hashes for dead_simple_framework-0.4.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 741b2991bcd718e1a65c1465e3f4d110c3194ad1d3dbeb1ee4c11ccc22678a4e |
|
MD5 | d7997229c57cb64ce84217735bae965a |
|
BLAKE2b-256 | 9b7ba6d0c9d0b48f12a50573641cdff4df400c0b98592b457268c89bb20bb20a |
Close
Hashes for dead_simple_framework-0.4.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bb5c9b915065be6f4fda49cc1f662cbfb9beee6061f2d5433d91b6bd9515cba |
|
MD5 | b13993c661bbbd8ded72b189cd56ae19 |
|
BLAKE2b-256 | a176ec76118aa2ed72d50b3f37fc36e5f3d825043af211a894c8ecbe9a457f3d |