Skip to main content

Python SDK

Programmatic API for Python workflows using the synfire package.

Installation

Install Synfire to use the SDK:

pip install synfire

Quick Start

from synfire import Client

# Initialize the client
client = Client()

# Search for models
results = client.search("snn classifier", hardware_target="Pulsar")

# Download a model
model_path = client.pull("nrg-lab/snn-classifier")

# Load the NIR model
import nir
graph = nir.read(model_path / "model.nir")

Authentication

The SDK supports multiple authentication methods:

# Option 1: Environment variable (recommended for CI/CD)
# Set SYNFIRE_TOKEN in your environment

# Option 2: Explicit token
client = Client(token="synfire_your_token_here")

# Option 3: Use CLI authentication
# Run 'synfire login' first, then the SDK will use stored credentials
client = Client()

Client API Reference

Client.search()

Search for models in the registry.

results = client.search(
    query="snn",
    hardware_target="Pulsar",  # Optional: filter by hardware
    tags=["classification"],  # Optional: filter by tags
    limit=20,  # Optional: max results
)

Client.pull()

Download a model to a local directory.

# Pull latest version
path = client.pull("nrg-lab/snn-classifier")

# Pull specific version
path = client.pull("nrg-lab/snn-classifier", version="1.0.0")

# Pull to specific directory
path = client.pull("nrg-lab/snn-classifier", output_dir="./models")

Client.push()

Publish a model to the registry.

client.push(
    repository="nrg-lab/snn-classifier",
    version="1.0.0",
    model_path="./model.nir",
    card_path="./nir-card.json",
    release_notes="Initial release",  # Optional
)

Working with NIR Models

Synfire works seamlessly with the NIR library:

import nir
from synfire import Client

client = Client()

# Download and load a model
model_path = client.pull("nrg-lab/snn-classifier")
graph = nir.read(model_path / "model.nir")

# Inspect the model
print(f"Nodes: {list(graph.nodes.keys())}")
print(f"Edges: {graph.edges}")