Skip to main content

Really small Python class that extends native http.client.HTTPConnection allowing sending HTTP requests to Unix Sockets

Project description

HTTPUnixSocketConnection

Really small Python class that extends native http.client.HTTPConnection allowing sending HTTP requests to Unix Sockets

Installation

Poetry

poetry add httpunixsocketconnection

pip

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.

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

from httpunixsocketconnection import HTTPUnixSocketConnection

conn = 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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

httpunixsocketconnection-1.0.1.tar.gz (6.2 kB view hashes)

Uploaded Source

Built Distribution

httpunixsocketconnection-1.0.1-py3-none-any.whl (6.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page