-
Houdini’s embedded web server is a multi-threaded HTTP server written in C++ that can call Python functions (or C++ extensions) to handle web requests.
-
Its primary intended use is to build service-oriented APIs to access Houdini scene data.
-
There is only one global embedded web server for each running instance of Houdini.
-
You can specify path handlers using the hwebserver.urlHandler decorator, or build an API using the hwebserver.apiFunction decorator.
-
Then, you can start the embedded server using hwebserver.run:
hwebserver.run(8008, debug=True)
Note
If you call this function from a non-graphical session, it will not return (unless the server is interrupted or server code calls hwebserver.requestShutdown).
-
To try out the server from the command line:
-
Put the following code in a
server.py
file:server.py
import hou import hwebserver @hwebserver.urlHandler("/") def my_handler(request): return hwebserver.Response( "Hello from Houdini %s" % hou.applicationVersionString()) if __name__ == "__main__": hwebserver.run(8008, debug=True)
-
In a shell with the Houdini environment set up, run
hython server.py
. -
Point a browser to
http://127.0.0.1:8008/
to see the output. -
Stop the server by pressing ⌃ Ctrl + C (Linux and Mac) or ⌃ Ctrl + Break/⌃ Ctrl + ScrLk on Windows.
-
Subtopics ¶
Classes ¶
-
A request made to Houdini’s web server.
-
A response made back from Houdini’s web server.
-
A file uploaded in a request made to Houdini’s web server.
-
The general purpose HTTP handler.
-
The general purpose Async HTTP handler.
-
Base class for WebSocket support with the embedded server.
Starting and Stopping ¶
-
Starts Houdini’s web server.
-
Tells Houdini’s web server to shut down after serving all open requests.
-
Returns True if Houdini’s web server was started in debug mode debug=True in )
Handling Web Requests and Returning Responses ¶
-
Decorator for functions that handle requests to Houdini’s web server.
-
Generates a Response object representing an HTTP error.
-
Generates a Response object representing a 404 Not Found HTTP error.
-
Generates a Response object that sends the contents of a file.
-
Generates a Response object representing a 301 Moved or 302 Found HTTP response.
-
hwebserver.registerStaticFilesDirectory
Tells Houdini’s web server to check the given directory for files to automatically serve for URLs that match the given path prefix.
-
Function used to register a wsgi capable application such as django to be used on a path prefix.
-
Function used to register a asgi capable application such as django to be used on a path prefix.
-
Set the settings for a specific port.
WebSocket ¶
-
Base class for WebSocket support with the embedded server.
-
Decorator for registering WebSocket classes with Houdini’s web server.
API Calls ¶
-
Decorator for functions that can be called through an API endpoint on Houdini’s web server, returning JSON or binary responses.
-
Raise this exception in apiFunction handlers to indicate an error.