Skip to main content

HTTPD Python Server

Installation and usage

pip install pyserv
serv [port]

Examples :

serv 8080

The output would be

...
INFO:root:Starting HTTP SERVER at PORT 8080

GET and POST request example

Open a new terminal and try out sending GET and POST requests

$ python
>>> import requests
>>> URL = 'http://0.0.0.0:8080'
>>> r = requests.get(URL)
>>> print(r.text)
GET request for /

On the server side you would get

INFO:root:GET  request,
Path: /
Headers:
Host: 0.0.0.0:8080
User-Agent: python-requests/2.21.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive



127.0.0.1 - - [18/Dec/2019 18:01:52] "GET / HTTP/1.1" 200 -

POST request to the server

>>> import requests
>>> URL = 'http://0.0.0.0:8080'
>>> r = requests.post(URL)
>>> print(r.text)
POST request for /

On the server side you will get

INFO:root:POST  request,
Path: /
Headers:
Host: 0.0.0.0:8080
User-Agent: python-requests/2.21.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Length: 0



Body:


127.0.0.1 - - [18/Dec/2019 18:03:07] "POST / HTTP/1.1" 200 -

If no port is mentioned the server attempts to run on port 8080.

If the given port (or the default port 8080) is already in use the server attempts to bind the next port. If the server does not find any free port after 50 attempts the server stops.

Link to the PyPI project : https://pypi.org/project/pyserv/ Motivation : https://gist.github.com/mdonkers/63e115cc0c79b4f6b8b3a6b797e485c7 (The Project is a extention of the github gist)

Metadata

Release files for pyserv 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyserv 1.1.1
File Size Uploaded
pyserv-1.1.1.tar.gz 3.5 kB Details

Release files / pyserv-1.1.1.tar.gz

Download URL pyserv-1.1.1.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
230de695e17491fe7de88385577adcdd8a136e2efc69e6d0c7e90db53cb59cd6
BLAKE2b-256 checksum
How to use checksums
4615234831c8b1f1b6e2569a42fbb115048c2234a8100dcf0df9911d992bcc83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

1.1.1 This release

1 release file

1.1.0

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page