Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 11 21:49
    fabaff opened #894
  • Nov 11 21:40
    fabaff opened #893
  • Oct 22 16:28
    Hantlowt opened #892
  • Sep 09 21:02
    egibert commented #501
  • Sep 07 23:31

    dependabot[bot] on pip

    (compare)

  • Sep 07 23:31
    dependabot[bot] closed #887
  • Sep 07 23:31
    dependabot[bot] commented #887
  • Sep 07 23:31
    dependabot[bot] labeled #891
  • Sep 07 23:31
    dependabot[bot] opened #891
  • Sep 07 23:31

    dependabot[bot] on pip

    Bump pillow from 6.2.0 to 8.3.2… (compare)

  • Sep 07 21:08
    buko106 edited #889
  • Sep 06 04:09
    buko106 edited #889
  • Sep 06 04:09
    buko106 opened #890
  • Sep 06 03:53
    buko106 opened #889
  • Jun 25 17:39
    KyleKing edited #886
  • Jun 14 14:23
    ptitpoulpe opened #888
  • Jun 08 18:55

    dependabot[bot] on pip

    (compare)

  • Jun 08 18:55
    dependabot[bot] closed #883
  • Jun 08 18:55
    dependabot[bot] commented #883
  • Jun 08 18:55
    dependabot[bot] labeled #887
Frank Berghaus
@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
@timothycrosley
@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/
x10an14
@x10an14
@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
@timothycrosley
@x10an14 you are correct! https://hugapi.github.io/hug/ is a better link
Priyanka Garg
@garg-priyanka

Hi, I am just starting with Hug.

How can I pass a custom directive into a middleware.

Elvis Stansvik
@estan

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

import hug
import cbor

@hug.format.content_type('application/cbor')
def cbor_format(data, request=None, response=None):
    return cbor.dumps(data)

@hug.get(format=cbor_format)
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
@estan
nevermind :facepalm: the name of the argument is output, not format.
Timothy Edmund Crosley
@timothycrosley
@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
@cryptoflipper
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
@timothycrosley
Happy to hear!
ConorDonohoe
@ConorDonohoe
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.
SimonShapiro
@SimonShapiro

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.

sylvoslee
@sylvoslee
Is there any news about hug3.0?
Programacion-Medellin47
@Programacion-Medellin47
Hello people! You can help me? I want to know how change the response status with hug
codingadvocate
@codingadvocate
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"
codingadvocate
@codingadvocate
Probably better to discuss this over a ticket... so: Preprocessing Falcon request object stopped working #833
codingadvocate
@codingadvocate
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.
ptitpoulpe
@ptitpoulpe
hello, there is a way to have SSE or WebSocket with hug/uwsgi ?
Pradhvan Bisht
@Pradhvan
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
@bartzy
is this channel active?
Pradhvan Bisht
@Pradhvan
@bartzy I don't think so
eelancecq
@eelancecq
hi,
is there any way to get the client connection ip when use hug?
David Alberto Casas A.
@Daca1953
hi, someone know how to allow the permission of CORS, to make a httpRequest from other url?
zdw3277024
@zdw3277024
What should I do to access the hug with ipv6 address
Andrea Ghensi
@andrea.ghensi_gitlab
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?
codingadvocate
@codingadvocate
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
ptitpoulpe
@ptitpoulpe
Hello, I wonder what is the better way to handle sqlalchemy session in hug
John Galt
@johngalt2600
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:
#!/bin/sh
''''exec hug -f "$0" ${1+"$@"} # '''
Just replace your normal #!/usr/bin/env python line at the top of your program with that.
John Galt
@johngalt2600
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
@johngalt2600
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
@johngalt2600

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

ptitpoulpe
@ptitpoulpe
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
@harryhua:matrix.org
[m]
hi
anyone can help me ?
i got a error "command not found: hug" after I use "pip3 install hug -U"
Harry Ren
@harryhua:matrix.org
[m]
is my zsh path problem , already fixed , thank you
Vytautas Liuolia
@vytas7

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.

hazem-hosny
@hazem-hosny
No Konaysa Kalthom
Sachin Sangwan
@sachinsangwan:matrix.org
[m]
hi @timothycrosley ........................... I am using hug python for api and want to fetch the client ip address on their call to my api but i am not able to do so will you please help me out with this
Marco Giuliano
@digEmAll

Hi All, probably a noob question, but I couldn't find it anywhere on the doc... would it be possible to automatically log all falcon exceptions ?
At the moment I have simply overridden the LogMiddleware like this:

@hug.middleware_class()
class MyHugLogger(LogMiddleware):
    def __init__(self, logger=my_logger):
        super().__init__(logger=logger)

but this seems to only "briefly" log the requests (timestamp-url-status-agent)

Thanks in advance