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.

Installation

To install the package, use pip:

pip install nexosim-py

Example

Given a server implementation:

use nexosim::model::Model;
use nexosim::ports::{EventSource, EventBuffer, Output};
use nexosim::registry::EndpointRegistry;
use nexosim::simulation::{Mailbox, SimInit, Simulation, SimulationError};
use nexosim::time::MonotonicTime;
use nexosim::server;

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

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

impl Model for AddOne {}

fn bench(_cfg: ()) -> Result<(Simulation, EndpointRegistry), SimulationError> {
    let mut model = AddOne::default();

    let model_mbox = Mailbox::new();
    let model_addr = model_mbox.address();

    let mut registry = EndpointRegistry::new();

    let output = EventBuffer::new();
    model.output.connect_sink(&output);
    registry.add_event_sink(output, "add_1_output").unwrap();

    let mut input = EventSource::new();
    input.connect(AddOne::input, &model_addr);
    registry.add_event_source(input, "add_1_input").unwrap();

    let sim = SimInit::new()
        .add_model(model, model_mbox, "Adder")
        .init(MonotonicTime::EPOCH)?
        .0;

    Ok((sim, registry))
}


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.start()
    sim.process_event("add_1_input", 5)

    print(sim.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.1.0.tar.gz (50.9 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.1.0-py3-none-any.whl (37.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nexosim_py-0.1.0.tar.gz
  • Upload date:
  • Size: 50.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for nexosim_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 46d5a2ece3ce353f1b2afda121b0d138b6f4fd616a20b413a7f564bf4cfb8498
MD5 9d3a60ed1e4178793a45c7fffeab1d1c
BLAKE2b-256 24ea8284d1acfb0b5db0073d1e19a13d612783c6804f5d4bfb8f251bcbcdc5ec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nexosim_py-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 37.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for nexosim_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83126b41f2128e952c0411f543018e13d1e449cc340d39f6a440d7911b807486
MD5 50767b25011c4d3db8acbc62ff443de6
BLAKE2b-256 9029f95c6c5a610fd1b57ba4d77607a1a35a203bf0e62d71ef639771f5eb0bb6

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