Skip to main content

Socket.Socket Subclass for Sending Numpy Arrays

Project description

NumpySocket

GitHub Sponsor

About

Provides a subclass of socket.socket that enables a TCP/IP socket that can send and recieve Numpy arrays with the same interface as a regular Python socket.

Methods

The subclass of socket.socket provides three key method overrides. All other socket methods are untouched.

  • sendall - takes a Numpy array as an argument to send an Array
  • recv - outputs a Numpy array (len() == 0 if no data received)

Known Issues

With a large value for bufsize in recv() there it is not guaranteed that multiple small arrays will be fully received. You should always set your bufsize to be small enough that it will not "reach over" to the next array.

Installation

pip install numpysocket

Examples

There are two separate examples showing how to create a client and sever using a NumpySocket

Simple

./examples/Simple shows a server which closes after the client disconnects.

In terminal 1, run:

python simple_server.py 

In terminal 2, run:

python simple_client.py

OpenCV

./examples/OpenCV shows an actual usecase for this library (sending video frames). This example requires installing additional requirements (./examples/openCV/requirements.txt).

This example also shows how to create a persistent server which allows for new clients to connect after old clients disconnects.

In terminal 1, run:

python cv_server.py 

In terminal 2, run:

python cv_client.py

Kill terminal 2 and re-run the command and the server will allow for the new connection.

Dev

install uv

pip install uv

install in editable mode

uv venv
uv pip install -e .

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

numpysocket-2.0.2.tar.gz (30.6 kB view details)

Uploaded Source

Built Distribution

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

numpysocket-2.0.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file numpysocket-2.0.2.tar.gz.

File metadata

  • Download URL: numpysocket-2.0.2.tar.gz
  • Upload date:
  • Size: 30.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.5

File hashes

Hashes for numpysocket-2.0.2.tar.gz
Algorithm Hash digest
SHA256 042d1499633eaef17baad4998a89ae3c0674be1b890733aaa47e7ab213fd76d7
MD5 5e8841cd3321d29b065b9b11913c8158
BLAKE2b-256 8818710b9a97b469b6f2d045eeb3848b94a91c0be3ba31dce30b1c1b4c48b780

See more details on using hashes here.

File details

Details for the file numpysocket-2.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for numpysocket-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 94f470fb6077ffd60fa099f5ed64c021bf07d5f6468b1eba85e0b95300ca4189
MD5 55cac47fccf4cd853e0d7ef88117b2cf
BLAKE2b-256 500fef12ebf5a98742b6433d169a054ad956b34b732195a46a4be9b2f3771a9d

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