DEV Community

vast cow
vast cow

Posted on Edited on

AF_UNIX compatibility for Windows Python

AF_UNIX compatibility for Windows Python

afunix-windows provides two importable compatibility modules:

  • af_unix_asyncio_compat implements the asyncio Unix-domain socket APIs.
  • af_unix_socket_compat implements synchronous, socket-style Unix-domain APIs.

On Unix-like platforms the modules delegate to Python's standard library. On Windows they use native Winsock AF_UNIX support, including a ctypes fallback for runtimes which do not expose all of the required functionality.

Installation

python -m pip install git+https://github.com/vast-cow/afunix-windows-py.git
Enter fullscreen mode Exit fullscreen mode

Python 3.10 or newer is required.

Asyncio usage

from af_unix_asyncio_compat import open_unix_connection, start_unix_server

reader, writer = await open_unix_connection("./example.sock")
server = await start_unix_server(client_connected_callback, "./example.sock")
Enter fullscreen mode Exit fullscreen mode

Synchronous usage

import af_unix_socket_compat as unix_socket

client = unix_socket.create_connection("./example.sock")
server = unix_socket.create_server("./example.sock", cleanup_socket=True)
Enter fullscreen mode Exit fullscreen mode

Both modules expose an explicit install() migration helper. Prefer direct imports in new applications because install() globally monkey-patches the corresponding standard-library module.

See spec.md for API details, complete examples…

Top comments (1)

Collapse
 
asking profile image
asking • • Edited

What is this licensed under and is there a repo somewhere hosting this?