A little client for applications driven by numpy
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
Numpy with Apache Arrow Flight
A Problem
We provide
- An abstract base class for an Apache flight server
- A client class to communicate with such servers
We efficiently transfer NumPy arrays over Apache Arrow Flight using a custom Client. The client provides a simple interface for sending NumPy arrays, performing computations, and retrieving results, all while handling the serialization and deserialization automatically in the background.
To create a server we expect the user to overload a function performing the calcutation based on a dictionary of numpy arrays.
Features
- Seamless conversion between NumPy arrays and Arrow Tables
- Simple interface for data transfer operations
- Support for batch computations
- Automatic resource management
- Type-safe operations with proper error handling
Installation
You can install this client via
pip install numpy-flight
Usage
Basic Setup
import numpy as np
import pyarrow.flight as fl
from np.flight import Client
# Initialize the Flight client
flight_client = fl.FlightClient('grpc://localhost:8815')
client = Client(flight_client)
Sending Data
# Prepare your NumPy arrays
data = {
'values': np.array([1, 2, 3, 4, 5]),
'labels': np.array(['a', 'b', 'c', 'd', 'e'])
}
# Send data to the server
client.write('store_data', data)
Retrieving Data
# Get data from the server
result_table = client.get('retrieve_data')
Computing with Data
# Send data and get results in one operation
input_data = {
'x': np.array([1, 2, 3]),
'y': np.array([4, 5, 6])
}
results = client.compute('multiply_arrays', input_data)
API Reference
Client
__init__(client: fl.FlightClient)
Initialize the client with a Flight client instance.
write(command: str, data: Dict[str, np.ndarray])
Write NumPy arrays to the Flight server.
command: String identifying the operationdata: Dictionary mapping column names to NumPy arrays
get(command: str) -> pa.Table
Retrieve data from the Flight server.
command: String identifying the data to retrieve- Returns: PyArrow Table containing the retrieved data
compute(command: str, data: Dict[str, np.ndarray]) -> Dict[str, np.ndarray]
Perform a computation on the server and retrieve results.
command: String identifying the computationdata: Input data as dictionary of NumPy arrays- Returns: Dictionary of NumPy arrays containing results
Error Handling
The client includes proper error handling for common scenarios:
FlightError: Raised for Flight protocol communication errorsValueError: Raised for data conversion errors- Resource cleanup is handled automatically, even in error cases
Best Practices
- Always close the Flight client when done:
client.close()
- Use context managers when possible to ensure proper cleanup:
with flight.FlightClient('grpc://localhost:8815') as flight_client:
client = Client(flight_client)
# ... perform operations
- Handle large datasets in chunks to manage memory usage effectively.
Set Up Environment
make install
This installs/updates uv, creates your virtual environment and installs dependencies.
For adding or removing packages:
uv add/remove requests # for main dependencies
uv add/remove requests --dev # for dev dependencies
Contributing
- Fork the repository
- Create your feature branch (git checkout -b feature/amazing-feature)
- Commit your changes (git commit -m 'Add some amazing feature')
- Push to the branch (git push origin feature/amazing-feature)
- Open a Pull Request
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file numpy_flight-0.0.4.tar.gz.
File metadata
- Download URL: numpy_flight-0.0.4.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ced24e06d958a24395756d74659829d17e35ff223ee1ffa829c1be3e8199592
|
|
| MD5 |
96813d7eff4d913dbf1bb2177a64ecf6
|
|
| BLAKE2b-256 |
3a1d0cf87bf4163f7fce6ff7a5f0490cdaa077bef0825fb24ad5a75388f76f5a
|
Provenance
The following attestation bundles were made for numpy_flight-0.0.4.tar.gz:
Publisher:
release.yml on tschm/numpy-flight
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
numpy_flight-0.0.4.tar.gz -
Subject digest:
3ced24e06d958a24395756d74659829d17e35ff223ee1ffa829c1be3e8199592 - Sigstore transparency entry: 172180784
- Sigstore integration time:
-
Permalink:
tschm/numpy-flight@b42b513cb232c637b68ff70d60472d5aa0563f8e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tschm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b42b513cb232c637b68ff70d60472d5aa0563f8e -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file numpy_flight-0.0.4-py3-none-any.whl.
File metadata
- Download URL: numpy_flight-0.0.4-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a32540ddbea92061d9c825341176e5ed1a2e571068b2e75f19198f5ab7bd60fe
|
|
| MD5 |
87a897e09303cacdd9892fb5cba127c4
|
|
| BLAKE2b-256 |
cbb98f0d004858de75a133fcf7b7af1a4e5ebfe179b97f4de57837b6a1cd2f97
|
Provenance
The following attestation bundles were made for numpy_flight-0.0.4-py3-none-any.whl:
Publisher:
release.yml on tschm/numpy-flight
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
numpy_flight-0.0.4-py3-none-any.whl -
Subject digest:
a32540ddbea92061d9c825341176e5ed1a2e571068b2e75f19198f5ab7bd60fe - Sigstore transparency entry: 172180785
- Sigstore integration time:
-
Permalink:
tschm/numpy-flight@b42b513cb232c637b68ff70d60472d5aa0563f8e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tschm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b42b513cb232c637b68ff70d60472d5aa0563f8e -
Trigger Event:
workflow_dispatch
-
Statement type: