Questions tagged [hug]

Hug is Python3 API development framework built upon falcon.

Hug aims to make developing Python driven APIs as simple as possible, but no simpler. As a result, it drastically simplifies Python API development.

31 questions
7
votes
4 answers

python hug api return custom http code

After looking for it for quite a while and asking on: https://gitter.im/timothycrosley/hug I'm unable to find a solution. what I'm looking for is a way to return a custom http code, lets say 204 in case a condition is met in the get end point. the…
Nick Kobishev
  • 157
  • 4
  • 13
5
votes
2 answers

How can I get request headers with python hug

In a function annotated as a hug api call, how can I get the headers for that call?
monty0
  • 1,759
  • 1
  • 14
  • 22
4
votes
3 answers

Changing Port on HUG

Is it possible to change the port number on HUG for python? I have the following sample of what I'm trying to do. The API defaults to port 8000 but I want to be able to set it manually. @hug.post() def receive_json(request): …
brandonunited
  • 83
  • 2
  • 6
4
votes
0 answers

How to get the URL for a route in hug?

In flask, one can easily get the URL for a given endpoint using url_for(). Is there an equivalent in Hug? I'd like to automatically generate the URLs for various resources in my REST API for inclusion in the responses.
leecbaker
  • 3,611
  • 2
  • 35
  • 51
3
votes
1 answer

Passing path like string in hug server

Is there any way to pass a string with slashes in hug, for example with this function: import hug @hug.get("/returnfilecontent/{path}") def doubles(path): return open(path, 'r').read() I want to access to…
somenxavier
  • 1,206
  • 3
  • 20
  • 43
3
votes
1 answer

How to send a pandas dataframe using POST method and receive it in Hug/other REST API framework? pickle.loads fails to unpickle after sending

How to send a pandas DataFrame using a POST method? For example, the following hug server listens to a POST requests and responds with a pickled pandas DataFrame: import hug import pickle import traceback import pandas as pd @hug.post() def…
Greg
  • 8,175
  • 16
  • 72
  • 125
3
votes
1 answer

Using PyTest with hug and base_url

I have a an api that is setup with import hug API = hug.API(__name__).http.base_url='/api' @hug.get('/hello-world', versions=1) def hello_world(response): return hug.HTTP_200 and I'm trying to test it with PyTest. I'm trying to test the route…
YourWebDevGuy
  • 73
  • 1
  • 8
3
votes
2 answers

How to upload a file to Hug REST API

I'm working on a basic Hug API and one of my functions needs a file. Does Hug have a way to upload a file?
bzupnick
  • 2,646
  • 4
  • 25
  • 34
2
votes
3 answers

Handling function param that can str or list in Python

I'm not an experienced Python programmer but I feel my solution to this problem isn't right, I think there is a better way to deal with this problem in Python. In this case, this is using Hug API but that's probably mostly irrelevant. Let's say the…
ETL
  • 9,281
  • 3
  • 29
  • 28
2
votes
1 answer

I do not understand where the slashes in json come from in the server's response

In the main function, i call a function in which another application is called, as a result i get data in json format. But I don’t understand where the slashes come from in front of each double quotation " in the browser, I see data with…
2
votes
0 answers

CLI routing not working with @hug.extend_api()

I'm trying to use @hug.extend_api() for CLI routes but it's not working. Calling hug -f run.py -c something, the command list is empty. The same code works fine for HTTP routing. This is my main script (run.py): import hug from apitest import…
Eduardo Marinho
  • 446
  • 4
  • 14
2
votes
1 answer

python hug - Cannot use Nested in MarshmallowSchema

Using HUG for building a Rest API, VERSION 2.3.0 (https://github.com/timothycrosley/hug) I cannot use the Nested ability of Marshmallow in HUG. Here is some code. import config from tinydb import TinyDB, Query import hug import hashlib import…
André
  • 24,706
  • 43
  • 121
  • 178
2
votes
2 answers

Making Python decorators work with the Hug API framework

I am fairly new to Python. I am building a simple API using Hug. I am trying to use a decorator to handle all not handled exceptions as in the code below. But it appears I am not passing inputs required by Hug in the decorator properly. auth.py…
Moon
  • 33,439
  • 20
  • 81
  • 132
2
votes
1 answer

Debugging python hug api with pdb

I'm trying to debug a python hug API with pdb. The regular hug api is started with: hug -f api.py You can start pdb from the command line via python interpreter using: python -m pdb api.py Where api.py contains hug routes, directives etc. api.py…
bucabay
  • 5,235
  • 2
  • 26
  • 37
2
votes
1 answer

Logging with hug and waitress

I want to add logging to my Python hug REST app. I couldn't find any wayto do it when serving the app through the hug command (via hug -f app.py), therefore I try to combine hug with waitress. My minimal app structure in the file app.py looks…
halloleo
  • 9,216
  • 13
  • 64
  • 122
1
2 3