Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marverix/httpunixsocketconnection
Really small Python class that extends native http.client.HTTPConnection allowing sending HTTP requests to Unix Sockets
https://github.com/marverix/httpunixsocketconnection
linux python3 python3-library socket sockets unix unix-domain-socket unix-domain-sockets
Last synced: 10 days ago
JSON representation
Really small Python class that extends native http.client.HTTPConnection allowing sending HTTP requests to Unix Sockets
- Host: GitHub
- URL: https://github.com/marverix/httpunixsocketconnection
- Owner: marverix
- License: apache-2.0
- Created: 2022-04-02T12:29:06.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-04-02T13:49:05.000Z (over 2 years ago)
- Last Synced: 2024-09-14T23:52:38.705Z (2 months ago)
- Topics: linux, python3, python3-library, socket, sockets, unix, unix-domain-socket, unix-domain-sockets
- Language: Python
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTTPUnixSocketConnection
Really small Python class that extends native http.client.HTTPConnection allowing sending HTTP requests to Unix Sockets
## Installation
### Poetry
```sh
poetry add httpunixsocketconnection
```### pip
```sh
pip install httpunixsocketconnection
```## Usage
Because the class base is `http.client.HTTPConnection`, the API is almost the same.
Only the constructor and `connect` method is different.
With the rest please follow [the official docs](https://docs.python.org/3.8/library/http.client.html#http.client.HTTPConnection).```python
from httpunixsocketconnection import HTTPUnixSocketConnection# Create a connection
conn = HTTPUnixSocketConnection(
unix_socket="/var/run/some.unix.socket"
# timeout=Like in HTTPConnection
# blocksize=Like in HTTPConnection
)
```### Example: Getting list of Docker Containers
```python
from httpunixsocketconnection import HTTPUnixSocketConnectionconn = HTTPUnixSocketConnection("/var/run/docker.sock")
conn.request("GET", "/containers/json")res = conn.getresponse()
print(res.status, res.reason)content = res.read().decode("utf-8")
print(content)
```