HTTP Server
Server which runs Hyper Text Transport Protocol
Check it out at PYPI
Server parameters
config=ConfiguratorSpecify a configurator. UseFluentConfiguratorfor type hints orConfiguratorfor plain textloglevel=LogLevel.loggingChoose a logging or console form reportingrefresh_rate=0.1Socket connection refresh ratecache_max_size=4e9Max cache size
Download
pip install ihttpy
Fluent Example
import ...
config = FluentConfigurator()
@config.on(Method.GET).at('/')
def index(req: Request, srv: Server)
return Response(200, 'OK')
config._host = '0.0.0.0'
config._port = 8000
server = Server(config, loglevel=LogLevel.CONSOLE)
with server as s:
s.run()
Running the tests
python3 -m unittests discover tests/
Plaintext Config settings
-
rulesIs a map with regular language- use square braces for any match (same as .*? in re)
- type [
name] inside braces to set named group - use match names in found path
example:
query"/[day]-[n]/[month]/[year]" : "/pictures/[year]/[month]/[day]/[n].pnglocalhost:8000/27-me/09/2000will display a photo/pictures/2000/09/27/me.pngif exists
-
hostChose server host- use
localhostto run locally
- use
-
portSpecify port for server to listen- default is
8000
- default is
-
error-pagesused by Errors class
Dynamic handlers configuration
if you want more handling control:
- specify
pathfield for static file response - use
handlerobject description assourceto choose handler pathpostname of function to handle POST requestgetname of function to handle GET request
- specify
headersfor additional headers to be added
-
static file response
localhost:8000/my_guest_bookurl"/my_guest_book": "tmp/my_guest_book.html",router will match this url and send file
tmp/my_guest_book.html -
custom GET handler for
localhost:8000/postsurl"/posts": { "handler": { "source": "handlers/my_guest_book.py", "get": "get_posts" } }this will start loaded
sourcehandler search for url and callget_postsfunction -
custom POST handler for
localhost:8000/posturl"/post": { "handler": { "source": "handlers/my_guest_book.py", "post": "handle_post" } }it will call
handle_postfunction fromsourcefound handler and process request in that module
Dynamic handlers usage
Handlers should be added as modules with 1 or 2 functions (which are
configured if config.json as it was described in
here)
Its signature needs to be
def function(request: Request, server: Server) -> Response:
Here you can use Server and Request that is being processed
Request structure:
self.method- request method (GET/POST)self.target- urlself.version- HTTP versionself.headers- headers dictionaryself.body- request body
Use this properties as you need to process the request
Logging and debug
If you want std.out as primary output use -l console
If you want file as output use -l logging
There is a logger.py for server info logging and debug, configure
LOGGER_PATH and LOG_DEBUG_PATH in defenitions.py
Author
- Ruslan Sirazhetdinov - Project creator, UrFU Student
Supervisor
- Viktor Samun - UrFU Python headquaters
Metadata
Release files for ihttpy 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ihttpy-2.1.0.tar.gz | 14.5 kB | Without provenance | Details for ihttpy-2.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ihttpy-2.1.0-py3-none-any.whl | Python 3 | none | any | Details for ihttpy-2.1.0-py3-none-any.whl |
Total release size: 30.8 kB
Release files / ihttpy-2.1.0.tar.gz
| Download URL | ihttpy-2.1.0.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f391b7bd07c5d1ad61192f3ecccdff7538cfab7f9a5ee6609c5bb67d0278b93
|
|
BLAKE2b-256 checksum How to use checksums |
c03492be29400c2598038aac3ae64adaa64b8bdb4c32a334b416df77a59ff630
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|
Release files / ihttpy-2.1.0-py3-none-any.whl
| Download URL | ihttpy-2.1.0-py3-none-any.whl |
|---|---|
| Size | 16.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2b19827eed81dd0f857634dd4b9932903375d8ae120531d876d2b299548376c6
|
|
BLAKE2b-256 checksum How to use checksums |
21877b0b65d463d58d48f056c17b5798329414f74b17b733b95b08accceec7cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|
Security for ihttpy 2.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.