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
Example Application (demo.py
):
* MongoDB must be running *
$ mongod
$ rabbitmq-server
$ celery -A demo worker -l info
from dead_simple_framework import Application, Task_Manager, Database, API
from random import randint
# A sample backend specified as a dictionary
sample_config = {
'routes': { # HTTP Routes available
'/demo': { # Route with automatic CRUD support
'name': 'demo',
'methods': ['GET', 'POST', 'DELETE', 'PUT'],
'template': None,
'defaults': None,
'logic': None,
'collection': 'demo'
},
'/': { # Route that runs an async task (addition)
'name': 'index',
'methods': ['GET'],
'template': None,
'defaults': None,
'logic': lambda: str(Task_Manager.run_task('add')),
},
'/insert': { # Another route with automatic CRUD support
'name': 'insert',
'methods': ['GET', 'POST', 'DELETE', 'PUT'],
'template': None,
'defaults': None,
'logic': None,
'collection': 'insert'
},
'/call': { # Route that runs an async task (API call)
'name': 'call',
'methods': ['GET'],
'template': None,
'defaults': None,
'logic': lambda: str(Task_Manager.schedule_task('call_api', ['http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json', {'item': 56}])),
},
'/last': { # Route that fetches a cached result from a scheduled task
'name': 'last_add',
'methods': ['GET'],
'template': None,
'defaults': None,
'logic': lambda: str(Task_Manager.get_result('rand_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,
'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`,
'cache': False # Disable caching
},
'call_api': { # API Call Task
'logic': lambda url, params=None: API.get_json(url, params),
},
'rand_add': { # Simple Addition Task (with random arguments)
'logic': lambda: randint(0, 1000) + randint(1, 10000),
'schedule': {}, # Default - every minute
},
}
}
# Required boilerplate to run the app or the scheduler [RabbitMQ must be running]
# Command line:
# Celery | celery -A <path.to.app> worker -l info
# App | python3 <app.py>
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 and returns the result of an asynchronous Celery task at endpoint
/
-
Runs an asynchronous chained value calculation and insert into the
insert
collection (viewable at/insert
) -
Runs an asynchronous API call and displays the result at endpoint
/call
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.2.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a5885e0a02fc904ff9cd56fa790d81d71bcb63193e75a8d4943d0029ffc8f5d |
|
MD5 | f06a067124fca0f43385c21d60b015e9 |
|
BLAKE2b-256 | fd284ebd22ce5f0b6466fbd08a1be2ff2f5db5a721f7a5caf9833676f8c3e9dd |
Close
Hashes for dead_simple_framework-0.2.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eec7271c96460b7be8c4e5d00f2ef45ddbd232eae1da3e76859299899bb7c0fe |
|
MD5 | e60661cd2006babfb37a4eac11c4e95f |
|
BLAKE2b-256 | 89e5c4935fff8a930f57875421f8ec3fa72731a095556a23f4b3c4e0187c6c79 |