Skip to main content

gRPC client library for Signal Fabric server

Project description

Signal Fabric Client

Official Python client library for Signal Fabric - a lightweight handler-based framework for generating market signals on demand.

Installation

pip install signal-fabric-client

Quick Start

from signal_fabric import GrpcClient

# Connect to Signal Fabric server
with GrpcClient(host='localhost', port=50051) as client:
    # Process a signal
    outcome = client.process_signal(
        target='BTC',
        signal_name='trend',
        signal_op='analyze'
    )

    # Check result
    if outcome.has_errors():
        print(f"Errors: {outcome.errors}")
    else:
        print(f"Result: {outcome.result}")
        print(f"Computed at: {outcome.computed_at}")

Usage

Basic Connection

from signal_fabric import GrpcClient, SignalOutcome

# Create client
client = GrpcClient(host='localhost', port=50051, timeout=30)
client.connect()

# Process signal
outcome = client.process_signal(
    target='ETH',
    signal_name='hello',
    signal_op='greet'
)

print(f"Result: {outcome.result}")

# Cleanup
client.disconnect()

Context Manager (Recommended)

from signal_fabric import GrpcClient

with GrpcClient(host='localhost', port=50051) as client:
    outcome = client.process_signal(
        target='BTC',
        signal_name='trend',
        signal_op='analyze',
        handler_request={'period': 14}
    )

    print(f"Result: {outcome.result}")

With Request Parameters

with GrpcClient() as client:
    outcome = client.process_signal(
        target='BTC',
        signal_name='composite_strategy',
        signal_op='analyze',
        handler_request={
            'period': 14,
            'threshold': 0.5,
            'timeframe': '1h'
        }
    )

Error Handling

from signal_fabric import GrpcClient

try:
    with GrpcClient(host='localhost', port=50051, timeout=10) as client:
        outcome = client.process_signal(
            target='BTC',
            signal_name='trend',
            signal_op='analyze'
        )

        if outcome.has_errors():
            print("Signal processing failed:")
            for error in outcome.errors:
                print(f"  - {error}")
        else:
            print(f"Success: {outcome.result}")

            # Access detailed results
            if outcome.is_detailed():
                print(f"Details: {outcome.details}")

except Exception as e:
    print(f"Connection failed: {e}")

API Reference

GrpcClient

Constructor

GrpcClient(host: str = 'localhost', port: int = 50051, timeout: int = 30)

Parameters:

  • host (str): Server hostname or IP address (default: 'localhost')
  • port (int): Server port number (default: 50051)
  • timeout (int): Request timeout in seconds (default: 30)

Methods

connect()

Establish connection to the server.

disconnect()

Close the connection to the server.

is_connected() -> bool

Check if client is currently connected.

process_signal(target, signal_name, signal_op, handler_request=None) -> SignalOutcome

Process a signal request.

Parameters:

  • target (str): Target for signal computation (e.g., 'BTC', 'ETH', 'AAPL')
  • signal_name (str): Signal handler name or profile name
  • signal_op (str): Operation to perform (e.g., 'analyze', 'greet')
  • handler_request (dict, optional): Request parameters as dictionary

Returns: SignalOutcome object

SignalOutcome

Result object containing the signal computation outcome.

Attributes

  • result (str): Signal result value
  • computation (str): Description of computation performed
  • computed_at (float): Unix timestamp when computed
  • errors (List[str]): List of error messages (empty if no errors)
  • details (Dict[str, str]): Additional computation details (empty if none)

Methods

has_errors() -> bool

Returns True if the outcome contains errors.

is_detailed() -> bool

Returns True if the outcome has errors or additional details.

Requirements

  • Python 3.8+
  • grpcio >= 1.76.0
  • protobuf >= 4.0.0

Server Setup

This client requires a running Signal Fabric server. To set up the server:

  1. Clone the Signal Fabric repository:

    git clone https://github.com/phasequant/signal-fabric.git
    cd signal-fabric
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Start the server:

    python src/server/server.py --config config.yaml
    

Examples

Multiple Signals

from signal_fabric import GrpcClient

signals = [
    ('BTC', 'trend', 'analyze'),
    ('ETH', 'volume', 'check'),
    ('SOL', 'momentum', 'calculate')
]

with GrpcClient() as client:
    for target, signal, operation in signals:
        outcome = client.process_signal(target, signal, operation)
        print(f"{target} {signal}: {outcome.result}")

Remote Server

from signal_fabric import GrpcClient

# Connect to remote server
with GrpcClient(host='signals.example.com', port=50051) as client:
    outcome = client.process_signal(
        target='BTC',
        signal_name='trend',
        signal_op='analyze'
    )
    print(f"Result: {outcome.result}")

Version

Current version: 0.1.3

License

See LICENSE file for details.

Links

Support

For questions, issues, or contributions, please visit the GitHub repository.

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

signal_fabric_client-0.1.3.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

signal_fabric_client-0.1.3-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file signal_fabric_client-0.1.3.tar.gz.

File metadata

  • Download URL: signal_fabric_client-0.1.3.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for signal_fabric_client-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2d41c0676353bacd8584f5ff27be5ba3a6d3c876733287e5c51b5e027e977df8
MD5 5156073c455273bd3009d5ac20d4769b
BLAKE2b-256 d54909bea5fc0d788482a97151586fd0db8f3378f8f91d9543691dd411f61894

See more details on using hashes here.

File details

Details for the file signal_fabric_client-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for signal_fabric_client-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2edb60c3afb258b4d76d576288fe2a4574c304bc9d1516f34f689d9e4b7e16b0
MD5 d8c6c3376901e3cb9ad1cf677981344e
BLAKE2b-256 a3ee2cd1ca9fc27c606bcd15b9d7cbafc0d6cfcf187706eb4b0616514f0dff25

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