Skip to main content

A single-threaded server for serving in-memory files via Unix sockets.

Project description

Unix Socket Server

A single-threaded server for serving in-memory files via Unix sockets. No Requirements. just clone this repo and copy unix_socket_server module to the root of your project or install package using pip:

pip install unix-socket-server

Problem

Imagine that we have a in-memory file in our Python application and we want to share this file with other apps or tools on the same host without writing it to disk.

Solution

A lightweight solution to this problem is to use Unix socket communication for file sharing.

Examples:

Use a context manager that automatically manages the server lifecycle:

from unix_socket_server import UnixSocketServerContext

with UnixSocketServerContext(b'hello world', '/tmp/file.sock') as server:
    """
        do stuff
    """

Or you can create and start the server manually.

server = UnixSocketServer(b'Hello World')
server.listen('/tmp/stream.socket')

UnixSocketServer writes file to response stream by default . but if your client needs http protocol you can use http handler like example below:

from unix_socket_server import UnixSocketServerContext
with open('./file-exmaple.txt', 'rb') as f:
    """
    UnixSocketServer also accepts readable io objects
    """
    with UnixSocketServerContext(f, '/tmp/file.sock', handler='http') as server:
        """
            do stuff
            dummy example:
                transport = httpx.HTTPTransport(uds=server.uri)
                client = httpx.Client(transport=transport)
                response = client.get('http://any_path/')
                assert response.status_code == 200
        """

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

unix-socket-server-0.0.5.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unix_socket_server-0.0.5-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file unix-socket-server-0.0.5.tar.gz.

File metadata

  • Download URL: unix-socket-server-0.0.5.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for unix-socket-server-0.0.5.tar.gz
Algorithm Hash digest
SHA256 dda40d68871ca689eb5ff0687b7e6762c09c86dcc778e8a70f76f4757e12bca2
MD5 abb675c13d4c6ac1aa0f83c858e6d7bd
BLAKE2b-256 2e4356ededdfea3f3882a0154c04fb16ab30b499ce8dc16d8d32893c65051458

See more details on using hashes here.

File details

Details for the file unix_socket_server-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for unix_socket_server-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 22a053ad6ae096e74f43bae689d18dd8be44faa49a1b4e5e639310db916f0874
MD5 d6e330b66bbe3821155fc89714f4d106
BLAKE2b-256 59f423db8fb34eb45e708d5155f7d1ef2dc27cef8d12b417e96d45f432807b81

See more details on using hashes here.

Supported by

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