Name: bluemix-python-eve-sample
Owner: IBM jStart
Description: This project is a Python-Eve Framework application backend deployed on IBM Bluemix™ that provides a practical illustration of setting up a python REST API to support mobile workloads and integration with 3rd party API platforms.
Created: 2015-07-17 13:19:56.0
Updated: 2018-01-22 18:46:11.0
Pushed: 2017-01-18 17:22:41.0
Homepage: null
Size: 1219
Language: Python
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This project is a Python-Eve Framework application (Flask-based) backend deployed on IBM Bluemix™ that provides a practical illustration of setting up a python server REST API to support mobile workloads and integration with 3rd party API platforms. After deployment, you'll have a REST API server that can be populated with the IEEE MA-L Public Listing. Using the first three-octet addresses (XX-XX-XX or XXXXXX), a deploy like this could be used as a lookup API and supports guidance given on the IEEE site for individuals interested in querying the public listing to download and parse the data locally. Some use cases include identifying if a client MAC Address is associated with a particular organization and identifying what three-octet addresses does an organization own. This sort of API can be handy in conjunction with Internet of Things (IoT) data analytics where MAC address data is common.
1.0
Cloud [~10 mins == A publicly visible deploy in the cloud. Sweet!]
Local Dev
Clone this repository to your local machine
Install and start a local MongoDB listening on default settings
Install dependencies to your local environment
$ pip install -r requirements.txt
Run Application
$ python macreduce/run.py
Data Population
To verify basic server access, browse to …
Invoke the appropriate custom endpoint to populate your deployed application with MAC Address Data hosted from the IEEE organizations site. This endpoint is protected via basic authentication. This will take a few minutes to process.
$ curl -u bluemix:devfun http://localhost:5005/populate
$ curl -u bluemix:devfun http://{enter_your_bluemixhost}.mybluemix.net/populate
Awesome. You now have a REST API server that can be used to cross-correlate the 3 leading pairs of a MAC Address with its owning Organization. Have fun. Here's an example of the type of query that you can try …
Fun Enhancement: Try to extend the model schema to also include the address information for an organization. Hint: You'll need to tweak the helper module which parses (and ignores the address info from) the IEEE raw data.
Event Hooks (NEW)
Python Eve supports pre-request, post-request and database event hooks. When a particular request is received, an event is raised. You can subscribe to these events with multiple callback functions. Database event hooks work like request event hooks. These events are fired before and after a database action.
This sample implements an example of a pre and post request event hook.
The hooks are configured within run.py. Enabling pre-request hooks involves syntax with on_pre while post-request hooks use on_post.
ting app instance (index 0) with guid d5xxxx-4e7f-xxxx-9206-dcxxxxxxxxx3
-08-12T02:09:06.73-0400 [App/0] OUT Welcome to Bluemix
-08-12T02:09:06.73-0400 [App/0] OUT Running on Python version: 2.7.11
-08-12T02:10:11.46-0400 [App/0] OUT Evaluating if Now is >= Criteria ...
-08-12T02:10:11.46-0400 [App/0] OUT Refresh criteria has been met
-08-12T02:10:11.46-0400 [App/0] OUT Begin MAC Address population ...
-08-12T02:10:11.46-0400 [App/0] OUT Deleting (reset) Mongo Collection named 'mac'
-08-12T02:10:11.46-0400 [App/0] OUT The best matched Accept-Language Header is: en (English)
-08-12T02:14:23.27-0400 [RTR/1] OUT macreduce.mybluemix.net - [12/08/2016:06:10:11.453 +0000] "GET /populate HTTP/1.1" 200 0 56 "-" "curl/7.43.0" 169.54.202.28:15063 x_forwarded_for:"23.114.41.234" x_forwarded_proto:"http" vcap_request_id:886b3293-5432-4a10-75fd-01b267cdde51 response_time:251.819555383 app_id:d5xxxx-4e7f-xxxx-9206-dcxxxxxxxxx3 x_global_transaction_id:"587954813"
-08-12T02:14:23.27-0400 [App/0] OUT Number of MAC Entries matched: 22213
-08-12T02:14:23.27-0400 [App/0] OUT {"message": "Whoaa! MacReduce Data Populated/Refreshed"}
-08-12T02:14:23.28-0400 [App/0] ERR 169.55.202.148 - - [2016-08-12 06:14:23] "GET /populate HTTP/1.1" 200 164 251.815483
Eve (Rest API framework) - latest develop Branch
GEvent (WSGI Server wrapper around Flask to bolster performance)
Requests (Module for invoking HTTP Requests to 3rd party platforms and APIs)
Python Eve-Docs - A blueprint that generates documentation for Eve APIs in HTML and JSON formats. Eve-docs creates the documentation from your existing Eve configuration file, with no additional configuration required. After deployment, it can be accessed at the api endpoint (/docs) example
Python Eve-Swagger (NEW) - Swagger extension for Eve powered RESTful APIs. After deployment, it can be accessed at the api endpoint (/api-docs) example
You can use the Swagger 2.0 compliant JSON output from this endpoint in conjunction with other swagger tooling to help document and manage access to your REST APIs. This also typically requires Cross-origin resource sharing (CORS) to be enabled. See Assumptions. Using the editor.swagger.io web application paired with the JSON output …
Test Jobs for the pipeline are defined within the .bluemix/pipeline.yml configuration file used by the deploy-to-bluemix button when setting up the devOps pipeline for the first time
Test Jobs are configured to kill/stop the pipeline if any failures are encountered
A SetupServices Deploy Job is included as a fallback for service creation if automatic creation via the deploy-to-bluemix button fails
Two executable (+x) bash shell scripts located within the tests folder
pep8_style_tests.sh : Purpose is to setup and run Flake8 syntax testing
nose_unit_tests.sh : Purpose is to setup and run nosetests for all unit tests within the tests folder
Providing them as source controlled files allows reuse within other projects
Python-Eve Framework StackOverflow
IEEE Public OUI Text Document - Updated Daily