Python hug.get() Examples
The following are 3
code examples of hug.get().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
hug
, or try the search function
.
Example #1
Source File: test_hug.py From scout_apm_python with MIT License | 6 votes |
def test_home(tracked_requests): with app_with_scout() as app: response = TestApp(app).get("/") assert response.status_int == 200 assert response.text == '"Welcome home."' assert len(tracked_requests) == 1 tracked_request = tracked_requests[0] assert tracked_request.tags["path"] == "/" assert tracked_request.active_spans == [] assert len(tracked_request.complete_spans) == 2 assert ( tracked_request.complete_spans[0].operation == "Controller/tests.integration.test_hug.home" ) assert tracked_request.complete_spans[1].operation == "Middleware"
Example #2
Source File: hug_api_example.py From python-examples with MIT License | 5 votes |
def a_redis_call(rname, ape=1): """Simple redis call.""" if ape == 1: return "no valid api key specified, nice try though".format(**locals()) if r.sismember('ape', ape) != 1: return "no valid api key specified, nice try though".format(**locals()) else: coolness = r.get(rname).decode('utf8') r.decr(ape) numleft = r.get(str(ape)) print(numleft) return "Authenticated w {ape}. You have {numleft} queries left. This\ is the {rname} value you requested: {coolness}".format(**locals())
Example #3
Source File: serve.py From nlp-architect with Apache License 2.0 | 4 votes |
def inference(request, body, response): """Makes an inference to a certain model""" print(body) if request.headers.get('CONTENT-TYPE') == 'application/gzip': try: original_data = gzip.decompress(request.stream.read()) input_docs = json.loads(str(original_data, 'utf-8'))["docs"] model_name = json.loads(str(original_data, 'utf-8'))["model_name"] except Exception: response.status = hug.HTTP_500 return {'status': 'unexpected gzip error'} elif request.headers.get('CONTENT-TYPE') == 'application/json': if isinstance(body, str): body = json.loads(body) model_name = body.get('model_name') input_docs = body.get('docs') else: response.status = status_codes.HTTP_400 return {'status': 'Content-Type header must be application/json or application/gzip'} if not model_name: response.status = status_codes.HTTP_400 return {'status': 'model_name is required'} # If we've already initialized it, no use in reinitializing if not services.get(model_name): services[model_name] = Service(model_name) if not isinstance(input_docs, list): # check if it's an array instead response.status = status_codes.HTTP_400 return {'status': 'request not in proper format '} headers = parse_headers(request.headers) parsed_doc = services[model_name].get_service_inference(input_docs, headers) resp_format = request.headers["RESPONSE-FORMAT"] ret = format_response(resp_format, parsed_doc) if request.headers.get('CONTENT-TYPE') == 'application/gzip': response.content_type = resp_format response.body = ret # no return due to the fact that hug seems to assume json type upon return else: return ret