Created
May 21, 2015 19:17
-
-
Save kageurufu/142c027dc1a6d55f7239 to your computer and use it in GitHub Desktop.
Example of loading large data in memory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
app = Flask(__name__) | |
from . import views |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from . import app | |
app.run('0.0.0.0', 5555) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uuid | |
BIG_DATA = {} | |
for i in range(10000): # 10,000 entries | |
BIG_DATA[str(uuid.uuid4())] = [n for n in range(i-5, i)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import request | |
import json | |
from . import app | |
from .data import BIG_DATA | |
@app.route("/") | |
def index(): | |
return json.dumps(BIG_DATA.keys()), 200 | |
@app.route("/<id>", methods=['GET', 'POST']) | |
def entry(id): | |
if request.method == 'POST': | |
if 'value' in request.values: | |
if id not in BIG_DATA: | |
BIG_DATA[id] = [] | |
BIG_DATA[id].append(request.values[value]) | |
return json.dumps(BIG_DATA[id]), 201 | |
else: | |
return 'value is required', 401 | |
elif request.method == 'GET': | |
if id in BIG_DATA: | |
return json.dumps(BIG_DATA[id]) | |
else: | |
return 'not found', 404 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment