Skip to main content

No project description provided

Project description

Neurion Ganglion - Ion Framework

Overview

Neurion Ganglion provides a framework for defining, deploying, and managing Ions – decentralized computational units that operate within the Neurion ecosystem. This repository offers a streamlined way to create and register Ions, either as self-hosted services or pre-existing services ready for registration.

Features

  • Define input and output schemas using Pydantic.
  • Register Ions with Neurion automatically or manually.
  • Health-check endpoints for ensuring service availability.
  • Auto-recovery mechanism for self-hosted Ions.
  • Easy-to-use decorators for defining execution logic.
  • Integrated Ganglion Server for managing pathways and processing Ion calls.
  • Support for both localnet and alpha testnet environments.

Installation

pip install neurion-ganglion

Network Configuration

Neurion supports multiple networks. Initialize a network configuration before using Ganglion or Ions:

from neurionpy.synapse.config import NetworkConfig

# Choose the appropriate network
config = NetworkConfig.neurion_localnet()  # For local development
# config = NetworkConfig.neurion_alpha_testnet()  # For testnet

Creating an Ion

You can create an Ion in two different ways:

1. Self-Hosting Ion (Auto-Registering)

This mode runs the Ion server locally and automatically registers it with Neurion.

from pydantic import BaseModel
from neurion_ganglion.ion.ion import Ion, ion_handler
from neurion_ganglion.custom_types.capacity import Capacity
from neurionpy.synapse.config import NetworkConfig

config = NetworkConfig.neurion_localnet()  # Set network config

# Define Input Schema
class MyInputSchema(BaseModel):
    task_id: str
    parameters: int

# Define Output Schema
class MyOutputSchema(BaseModel):
    message: str
    result: float

# Use decorator to attach schemas
@ion_handler(MyInputSchema, MyOutputSchema)
def my_ion_handler(data: MyInputSchema) -> MyOutputSchema:
    return MyOutputSchema(message="Success", result=12)

# Start Ion Server
if __name__ == "__main__":
    description = "My custom Ion server"
    stake = 20000000
    fee_per_thousand_calls = 1
    capacities = [Capacity.SCRAPER, Capacity.AI_AGENT]
    Ion.create_self_hosting_ion(config, description, stake, fee_per_thousand_calls, capacities, my_ion_handler).start()

2. Starting a Pure Ion Server & Registering it

If you want to set up multiple backend Ion servers and manually register them, you can start a pure Ion server first, note its public IP, and then use the registration function.

Step 1: Start the Pure Ion Server

from neurion_ganglion.ion.ion import Ion
from pydantic import BaseModel
from neurionpy.synapse.config import NetworkConfig

config = NetworkConfig.neurion_localnet()  # Set network config

# Define Input Schema
class MyInputSchema(BaseModel):
    task_id: str
    parameters: int

# Define Output Schema
class MyOutputSchema(BaseModel):
    message: str
    result: float

@ion_handler(MyInputSchema, MyOutputSchema)
def my_ion_handler(data: MyInputSchema) -> MyOutputSchema:
    return MyOutputSchema(message="Success", result=12)

# Start a pure Ion server
if __name__ == "__main__":
    Ion.start_pure_ion_server(config, my_ion_handler)

Step 2: Manually Register the Running Ion Server

Once the pure Ion server is running, note its IP address and use the following script to register it:

from neurion_ganglion.ion.ion import Ion
from neurion_ganglion.custom_types.capacity import Capacity
from neurionpy.synapse.config import NetworkConfig

config = NetworkConfig.neurion_localnet()  # Set network config

description = "My external Ion server"
stake = 20000000
fee_per_thousand_calls = 1
capacities = [Capacity.SCRAPER, Capacity.AI_AGENT]
endpoints = ["http://<noted-public-ip>:8000"]  # Replace <noted-public-ip> with actual IP

Ion.create_server_ready_ion(config, description, stake, fee_per_thousand_calls, capacities, MyInputSchema, MyOutputSchema, endpoints).register_ion()

Using Pathways

A Pathway defines a structured flow between multiple Ions.

from neurion_ganglion.ion.pathway import Pathway
from neurionpy.synapse.config import NetworkConfig

config = NetworkConfig.neurion_localnet()  # Set network config

# Initialize Pathway by ID
pathway = Pathway.of_id(config, 1)

# Call Pathway
response = pathway.call({"task_id": "1234", "parameters": 100})
print(response)

Ganglion Server

The Ganglion Server handles requests, routing them to the appropriate Ion or Pathway.

from neurion_ganglion.ganglion.server import GanglionServer
from neurionpy.synapse.config import NetworkConfig

config = NetworkConfig.neurion_localnet()  # Set network config

# Start Ganglion Server
GanglionServer.start(config)

Health Check

All Ions expose a /health endpoint that can be used to check their availability.

curl http://localhost:8000/health

License

This project is licensed under the MIT License.

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

neurion_ganglion-0.3.0.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

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

neurion_ganglion-0.3.0-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file neurion_ganglion-0.3.0.tar.gz.

File metadata

  • Download URL: neurion_ganglion-0.3.0.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.9.21 Linux/6.8.0-1021-azure

File hashes

Hashes for neurion_ganglion-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4f36a2b67381ca59d50c1dbcdb0a18f4bdeea75fbaf4a3df9cb1f9058898bcd3
MD5 f2e3fd53724748b9c67566c266140aae
BLAKE2b-256 0ff42949d4b123f7f8cc5159e07b6c2e7874c143fe1df7ce7399e50e85bf7982

See more details on using hashes here.

File details

Details for the file neurion_ganglion-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: neurion_ganglion-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.9.21 Linux/6.8.0-1021-azure

File hashes

Hashes for neurion_ganglion-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa8db088b0f369358292d7150bb13a33b2bd6c92755da5ef923c977e93c4e8e1
MD5 10708802603715dcf2a4e1be6e886ced
BLAKE2b-256 b2c4c26ff032c4c1a2ffa85d2a6322f1c186997d0eaf229b2d336fb008a60aed

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