Skip to main content

A gRPC client for the NeXosim simulator

Project description

NeXosim-py

NeXosim-py is a python interface for the NeXosim simulation server.

The library provides:

  • an interface to control and monitor simulations over HTTP/2 or unix domain sockets,
  • an API for the (de)serialization of Rust types,
  • asyncio support.

Compatibility

The package is compatible with NeXosim 0.3.2 and later 0.3.x versions. Supported python versions: 3.11, 3.12, 3.13, 3.14

Installation

To install the package, use pip:

pip install nexosim-py

Documentation

The latest documentation and the user guide can be found here.

Example

Given a server implementation:

use std::error::Error;

use nexosim::model::Model;
use nexosim::ports::{EventSource, Output, SinkState, event_queue_endpoint};
use nexosim::server;
use nexosim::simulation::{Mailbox, SimInit};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Default)]
pub(crate) struct AddOne {
    pub(crate) output: Output<u16>,
}

#[Model]
impl AddOne {
    pub async fn input(&mut self, value: u16) {
        self.output.send(value + 1).await;
    }
}

fn bench(_cfg: ()) -> Result<SimInit, Box<dyn Error>> {
    let mut model = AddOne::default();
    let model_mbox = Mailbox::new();

    let mut bench = SimInit::new();

    let output = event_queue_endpoint(&mut bench, SinkState::Enabled, "add_1_output")?;
    model.output.connect_sink(output);

    EventSource::new()
        .connect(AddOne::input, &model_mbox)
        .bind_endpoint(&mut bench, "add_1_input")?;

    Ok(bench.add_model(model, model_mbox, "Adder"))
}

fn main() {
    server::run(bench, "0.0.0.0:41633".parse().unwrap()).unwrap();
}

You can interact with the simulation using this library like this:

from nexosim import Simulation

with Simulation("0.0.0.0:41633") as sim:
    sim.build()
    sim.init()
    sim.process_event("add_1_input", 5)

    print(sim.try_read_events("add_1_output"))

# Prints out:
# [6]

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

nexosim_py-0.2.0.tar.gz (75.8 kB view details)

Uploaded Source

Built Distribution

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

nexosim_py-0.2.0-py3-none-any.whl (44.5 kB view details)

Uploaded Python 3

File details

Details for the file nexosim_py-0.2.0.tar.gz.

File metadata

  • Download URL: nexosim_py-0.2.0.tar.gz
  • Upload date:
  • Size: 75.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for nexosim_py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a7d1357b66ed27c668355f9ee3c238432799a3a11f715b543b9b338bb1198dcd
MD5 a75efa111f7699588976e9bdc54a941c
BLAKE2b-256 c05a0ff4f21eb4b7a2b392080c15e26c04c6ecf9a8d1765caf05fde169ffb649

See more details on using hashes here.

File details

Details for the file nexosim_py-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: nexosim_py-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 44.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for nexosim_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4916a2536c18027b4e0010b3a72a59f7808e3c71134035664750692b0908c9fd
MD5 670d6df67377461e88062829e17c099a
BLAKE2b-256 e6e461730ac69ec468573923f9c42397f6f66fcc8c94c048887148cd156a8445

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