Grole API¶
Grole is a python (3.5+) nano web framework based on asyncio. It’s goals are to be simple, embedable (single file and standard library only) and easy to use.
-
class
grole.
Grole
(env={})[source]¶ Bases:
object
A Grole Webserver
-
__init__
(env={})[source]¶ Initialise a server
env is passed to request handlers to provide shared state. Note, env by default contains doc which is populated from registered route docstrings.
-
-
class
grole.
Request
[source]¶ Bases:
object
Represents a single HTTP request
The following members are populated with the request details:
- method: The request method
- location: The request location as it is sent
- path: The unescaped path part of the location
- query: The query string part of the location (if present)
- version: The request version, e.g. HTTP/1.1
- headers: Dictionary of headers from the request
- data: Raw data from the request body
- match: The re.MatchObject from the successful path matching
-
class
grole.
Response
(data=None, code=200, reason='OK', headers={}, version='HTTP/1.1')[source]¶ Bases:
object
Represents a single HTTP response
-
__init__
(data=None, code=200, reason='OK', headers={}, version='HTTP/1.1')[source]¶ Create a response
Parameters:
- data: Object to send e.g. ResponseBody / ResponseJSON.
- code: The response code, default 200
- reason: The response reason, default OK
- version: The response version, default HTTP/1.1
- headers: Dictionary of response headers, default is a Server header and those from the response body
Note, data is intelligently converted to an appropriate ResponseXYZ object depending on it’s type.
-
-
class
grole.
ResponseBody
(data=b'', content_type='text/plain')[source]¶ Bases:
object
Response body from a byte string
-
class
grole.
ResponseFile
(filename, content_type=None)[source]¶ Bases:
grole.ResponseBody
Respond with a file
Content type is guessed if not provided
-
class
grole.
ResponseJSON
(data='', content_type='application/json')[source]¶ Bases:
grole.ResponseString
Response body encoded in json
-
class
grole.
ResponseString
(data='', content_type='text/html')[source]¶ Bases:
grole.ResponseBody
Response body from a string
-
grole.
main
(args=['-T', '-b', 'readthedocs', '-d', '_build/doctrees-readthedocs', '-D', 'language=en', '.', '_build/html'])[source]¶ Run Grole static file server
-
grole.
parse_args
(args=['-T', '-b', 'readthedocs', '-d', '_build/doctrees-readthedocs', '-D', 'language=en', '.', '_build/html'])[source]¶ Parse command line arguments for Grole server running as static file server