4

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):
    request=str(request)
    print("Hello! Glad you're here!")
    print(request)
    process=os.system("echo "+'"'+request+'"')
brandonunited
  • 83
  • 2
  • 6

3 Answers3

6

add at the end of your app.py (or whatever it's name is) file:

hug.API(__name__).http.serve(port=8005)

for serving on port 8005

mislavcimpersak
  • 2,880
  • 1
  • 27
  • 30
3

If you are using the hug command line script to start your app, the -p / --port option will get you there, as in hug --port 5000 -f app.py:

$ hug --help
usage: hug [-h] [-v] [-f FILE] [-m MODULE] [-p PORT] [-n] [-ma] [-i INTERVAL]
           [-c COMMAND]

Hug API Development Server

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -f FILE, --file FILE  file
  -m MODULE, --module MODULE
                        module
  -p PORT, --port PORT  A Whole number
  -n, --no_404_documentation
                        Providing any value will set this to true
  -ma, --manual_reload  Providing any value will set this to true
  -i INTERVAL, --interval INTERVAL
                        A Whole number
  -c COMMAND, --command COMMAND
                        command
Dirk
  • 9,381
  • 17
  • 70
  • 98
2

You can use Gunicorn to serve the hug app and use the -b flag to bind to a different port.

gunicorn --reload myapp:__hug_wsgi__ -b0.0.0.0:8008

YourWebDevGuy
  • 73
  • 1
  • 8