RESTful Flask framework with MongoDB, Redis and Celery integrations
Project description
🙈 Dead Simple Web Framework 🙉
Overview:
A RESTful Flask framework with MongoDB, Redis and Celery integrations:
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, RouteHandler, DefaultRouteHandler, Task
from random import choice
sample_config = {
'routes': {
'insert': Route( # A route with automatic CRUD support
url='/insert',
collection='insert',
),
'demo': Route( # Another route with automatic CRUD support (with all options specified)
url='/demo', # The URL at which the server should handle requests
defaults=None, # Default parameters to pass to the handler function for this URL
database='db', # The database that should be passed to the handler function for this URL
collection='demo', # The collection that should be passed to the handler function for this URL
handler=DefaultRouteHandler() # A class specifying the handler functions to use based on the method used to access the URL
),
'refresh': Route( # Route with a handler for the GET method that runs an async task (in this case an API call)
url='/api/refresh',
handler=RouteHandler(
GET=lambda request, payload: str(Task_Manager.run_task('scheduled_call'))
)
),
'index': Route( # Route that fetches the cached latest result of an async task (in this case an API call)
url='/',
handler=RouteHandler(
GET=lambda request, payload: str(Task_Manager.get_result('scheduled_call'))
)
),
'add': Route( # Route that runs an async task (in this case simple addition) and fetches the result
url='/add',
handler=RouteHandler(
GET=lambda request, payload: 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={}
)
}
}
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
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.9.9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c8a8a1e124c73e9725232d2df742a55ab5e9707ed8ad9d974be5fd00fc2a16f |
|
MD5 | 9ce4e51ed11b30d73881fc511a02a0ac |
|
BLAKE2b-256 | 18414b66469a0ba10caff0d08a7d7755f7cbb1561eb5b28185136c8037dd45c0 |
Close
Hashes for dead_simple_framework-0.9.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd7de0538b719febcae3f47cad09389b14d0d5707eb218e5740e9daf18608cf8 |
|
MD5 | d2d1a5ae4f2470e0d2facc20aab19856 |
|
BLAKE2b-256 | 7e8ed025adfdd09937a5d4c606d21c80359ff3f5e17d0391b389145c8185468e |