Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • Jun 14 14:23
    ptitpoulpe opened #888
  • Jun 08 18:55

    dependabot[bot] on pip


  • Jun 08 18:55
    dependabot[bot] closed #883
  • Jun 08 18:55
    dependabot[bot] commented #883
  • Jun 08 18:55
    dependabot[bot] labeled #887
  • Jun 08 18:55
    dependabot[bot] opened #887
  • Jun 08 18:55

    dependabot[bot] on pip

    Bump pillow from 6.2.0 to 8.2.0… (compare)

  • Jun 05 20:25
    KyleKing edited #886
  • Jun 05 20:24
    KyleKing opened #886
  • Jun 03 22:06
    mandeepm91 commented #592
  • May 27 09:20
    oersted commented #241
  • May 26 14:11
    ulmentflam commented #882
  • May 25 18:13
    JGabrielGruber commented #767
  • Apr 26 09:33
    piegamesde opened #885
  • Apr 18 03:46
    renhua91 commented #884
  • Apr 18 03:24
    renhua91 opened #884
  • Mar 18 20:14
    dependabot[bot] labeled #883
  • Mar 18 20:14
    dependabot[bot] opened #883
  • Mar 18 20:14

    dependabot[bot] on pip

    Bump pillow from 6.2.0 to 8.1.1… (compare)

  • Feb 08 21:01
    ulmentflam synchronize #882
@x10an14 Hahahahaha! Thanks!
Frank Berghaus

First off thanks for this framework, it was a super nice experience to get started here. Now I have found myself in a conundrum: I have a construct where I give my hug api a presigned URL. Hug seems to end up swallowing the signature however:

import hug

def test(url):
    return str( url)

The result looks like this:

curl http://localhost:8000/test -d url="https://some.s3.bucket/file?AWSAccessKeyId=XXX&Signature=YYY&Expires=123456789"

Where does the signature slug get munched up?

Frank Berghaus

Fixed it like so:

@hug.post("/test", map_params={"Signature": "sig", "Expires": "exp"})
def test(url, sig, exp):
    return "{}&Signature={}&Expires={}".format(url, sig, exp)

guess I am learning about reserved keywords :-)

Timothy Edmund Crosley
@berghaus glad you figured it out, and glad you are liking the framework!
@/all: New documentation site is live for hug http://hugapi.github.io/hug/
@timothycrosley Consider using https, so that those of us who are weary of random (shit tons) of JavaScript to be executed browser-side comes from a (somewhat) trusted source =)
Timothy Edmund Crosley
@x10an14 you are correct! https://hugapi.github.io/hug/ is a better link
Priyanka Garg

Hi, I am just starting with Hug.

How can I pass a custom directive into a middleware.

Elvis Stansvik

hi folks. i'm trying to make a custom output format which encodes as CBOR:

import hug
import cbor

def cbor_format(data, request=None, response=None):
    return cbor.dumps(data)

def test(request, response):
    return request.headers

but my cbor_format is not called and the data delivered as text/plain. i'm a hug noob so probably just misunderstanding something.

this is what i'm getting:
(venv) estan@edison:~/test$ curl http://localhost:8000/test
{"CONTENT-LENGTH": "", "CONTENT-TYPE": "text/plain", "HOST": "localhost:8000", "USER-AGENT": "curl/7.58.0", "ACCEPT": "*/*"}
Elvis Stansvik
nevermind :facepalm: the name of the argument is output, not format.
Timothy Edmund Crosley
@estan Glad you figured it out! @garg-priyanka Did you figure out how to accomplish this? This isn't something that hug is optimized for at the moment, but you can use directives from middlewares manually (passing in whatever arguments the directive takes, like a normal python function)
Mike Mindel
I just wanted to say thanks for the Hug API framework Timothy. It really is excellent and I use it for all my APIs at the moment.
Timothy Edmund Crosley
Happy to hear!
Hi would anyone be able to help me with the problem I am having trying to get the file name from an upload function, I've asked the question on Stack Overflow https://stackoverflow.com/questions/58508663/how-do-you-get-an-uploaded-file-name-from-hug-api-python thank you.

Hello. I am new to hug and very excited about its capabilities. I have an off-the-wall question though. Is there any way to programmatically determine the hosting url and port?

My use case is that I need to attach this info at run time to certain data fields.

Is there any news about hug3.0?
Hello people! You can help me? I want to know how change the response status with hug
For a couple years I've used a falcon middleware to dump the payload and authenticate the user, prior to allowing access to Hug wrapped functions. Hug versions 2.5.0 and prior worked with a rawData = request.stream.read(), and then resetting the stream with request.stream = io.BytesIO(rawData). But upgrading to the latest Hug (or anything 2.5.1 or newer), shows that the payload reset doesn't work and it appears empty - coming from hug\interface.py, exception in gather_parameters. Is this known/expected? Is there a work around with the newer Hug/Falcon? Should I freeze my project on an old Hug and file a bug? I use a Twisted WSGI, but created a 13 line unit test case that works with the 'hug -f file.py' command test: import hug, json, io from hug.types import text from hug.types import json as hugJson class AccessAndLoggerMiddleware: def process_resource(self, request, response, resource, parameters): rawData = request.stream.read() stream = io.BytesIO(rawData) request.stream = stream print('User: {}'.format(json.loads(rawData).get('user'))) hug.API(__name__).http.add_middleware(AccessAndLoggerMiddleware()) @hug.get('/test') def test(user:text, key:text, content:hugJson, request, response): return "Test"
Probably better to discuss this over a ticket... so: Preprocessing Falcon request object stopped working #833
Got a chance to dig into code diffs today, to find the culprit. Looks like between 2.5.0 and 2.5.1, hug.interface.gather_parameters() changes how it assigns the body. It moves from the previous falcon request.stream, over to the wrapped bounded_stream. And so the previous reset on request.stream won't work since bounded_stream would be empty from the stream read, and not reset by the new stream. I don't like overriding internal variables, but I have a work around by changing my code from "request.stream = io.BytesIO(rawData)", over to "request._bounded_stream = FalconBoundedStream(io.BytesIO(rawData), request.content_length)" and "from falcon.request_helpers import BoundedStream as FalconBoundedStream". I'll update the ticket accordingly.
hello, there is a way to have SSE or WebSocket with hug/uwsgi ?
Pradhvan Bisht
Hey! I was going through the documentation and found that the python code snippets aren't formatted correctly. Later realized that someone else had already opened a PR reading the issue hugapi/website#9
Since no one is working on the issue, I would love to pick it up.
@timothycrosley ^^
Bar Ziony
is this channel active?
Pradhvan Bisht
@bartzy I don't think so
is there any way to get the client connection ip when use hug?
David Alberto Casas A.
hi, someone know how to allow the permission of CORS, to make a httpRequest from other url?
What should I do to access the hug with ipv6 address
Andrea Ghensi
Hi there! I just found out about hug and I must admit it's really cool! I wonder why I haven't found it before, definitely better than flask and a ton of extensions!
I'm looking to use hug to expose an API for long running tasks, and I saw a post here and an issue on github mentioning celery... I wonder if someone has a working example on how to get it working.
I was thinking about a wrapper/decorator on top of hug.post, let's call it hug.post_async, that handles the call the celery task, and returns a 202 response with the url of a job status endpoint. Can it be done?
Hi Andrea. Sorry for the late response. Sure, that's possible. The work is basically taking a request (e.g. GET/POST), creating an identifier (URL) to hand back for continuing to check until it's done. I do that for pagination type requests for large datasets in the OCP project. You can see the Hug wrapped 'cache' functions that handle this, at the end of the following script... in case you want an example: https://github.com/opencontentplatform/ocp/blob/master/ocp/framework/lib/apiResourceQuery.py
Hello, I wonder what is the better way to handle sqlalchemy session in hug
John Galt
I was going to ask how to handle multiple functions in the cli but found hug -f myapp -c myroute in this gitter history... but who wants to add hug -f to every command? not me. So was going to ask how to modify the shebang so I can just do myapp -c myroute but a quick google search gave me the solution. So just a FYI in case anyone else wanted to do this. This worked for me:
''''exec hug -f "$0" ${1+"$@"} # '''
Just replace your normal #!/usr/bin/env python line at the top of your program with that.
John Galt
Looks that that works for valid commands, valid commands with invalid parameters, and help. But it has a bug that shows 'exec hug -f "$0" ${1+"$@"} # as part of the help when you use an invalid command
well, help doesn't work either, that shows help for hug not my program.
John Galt
You would think doing ''''exec hug -f "$0" -- ${1+"$@"} # ''' would fix the help problem but hug starts a web server instead of just running the program.
hug -f myapp -h also shows help for hug not myapp. hug -f mydata -- -h also starts in server mode.
John Galt

using a different shebang fixes the invalid command help.

#!/bin/env -S hug -f

But it still shows the help for hug instead of myapp when doing myapp -h

Hello, I’m using Hug with gunicorn, and gunicorn kill worker if request take more time than timeout and return a 502 error, I would like to return something else, do you know how to handle timeouts directly with hug, or if there is an handler when worker is killed ?
Harry Ren
anyone can help me ?
i got a error "command not found: hug" after I use "pip3 install hug -U"
Harry Ren
is my zsh path problem , already fixed , thank you
Vytautas Liuolia

Hi @timothycrosley !

I was wondering whether a new Hug version was planned / in the works that would take advantage of Falcon 3.0+?

I've tried running Hug's test suite with 3.0.0, and it seems the biggest breaking change causing multiple failures is the default Exception handler, that is always added to the app, unless the user provides their own, of course. The default handler no longer bubbles up the exception to the app server, but renders an HTTP 500 response.

I'm happy to answer any Falcon questions if needed, but OTOH I don't know that much about Hug's internals, so it wouldn't be me doing any advanced porting.

Furthermore, Falcon 3.0 adds optional ASGI support, so Hug could implement true async support, WebSocket, SSE etc. Also added was native multipart form parsing, and simple CORS support out of the box.

No Konaysa Kalthom