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

NeXosim-Py NeXosim
0.1.0 >=0.3.2 <0.4.0
0.2.x 1.0.0

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.1.tar.gz (76.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.1-py3-none-any.whl (44.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nexosim_py-0.2.1.tar.gz
Algorithm Hash digest
SHA256 57b61953e993b33f85100530da19b430c470067e7cb1fe912a0aff3c17b29519
MD5 de51ea976eb1bb309b71762209265757
BLAKE2b-256 20eb005cc097cdadb27bf926955b3610201bcf2cfbbd9755c5a90be5f8540b7f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for nexosim_py-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 08825d64fbbca842eb735af867946569709b87ab85eeee4aa1e6da6619eed4ae
MD5 0176c7f8a4f16f84972d87fe88b516be
BLAKE2b-256 e1abb5af451ae398609c96066795fbbdcdfd05c963555907736ace9ade7e3323

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