Python SDK

Engineering, in Python.

Connect a script to your workspace. Inspect a model, build repeatable studies, and bring simulation evidence into your own analysis.

GETTING STARTEDPython 3.12+Package: nsim-sdk
On this page
01

Install and connect

The SDK is a synchronous Python client for nsim. You’ll need Python 3.12 or later, access to an nsim project, and the SDK wheel supplied with developer access.

Install the supplied wheel
python -m venv .venv
source .venv/bin/activate
python -m pip install \
  ./nsim_sdk-0.1.0-py3-none-any.whl
Terminal

Replace the wheel path with the file you received. On Windows, activate the environment with .venv\Scripts\Activate.ps1. The distribution is named nsim-sdk; you import it as nsim.

Connect to your environment

In nsim, open Settings → API tokens. Create a token for the projects you want to use, with the read scope for this first connection. Set these environment variables through your shell or secret manager:

NSIM_GATEWAY_URL
The HTTPS gateway URL supplied for your nsim environment.
NSIM_API_TOKEN
Your project-scoped API token. Keep it outside your source code.

Client.from_env() reads these settings. The client makes requests when you call an operation; constructing the client does not open a connection.

02

Make your first read

Save this as discover.py, then run python discover.py. It lists up to ten documents your token can read.

discover.py
from nsim import Client

with Client.from_env() as client:
    page = client.documents.list(
        page_size=10
    )

    for doc in page.documents:
        print(doc.name)
        print(doc.document_id)
Python

Choose a document ID from the output and set it as NSIM_DOCUMENT_ID in your environment. Then read its metadata and model context:

inspect_model.py
import os
from nsim import Client

with Client.from_env() as client:
    document = client.documents.get(
        os.environ["NSIM_DOCUMENT_ID"]
    )
    snapshot = document.inspect(page_size=50)

    print(document.info.name)
    print(snapshot.revision)
Python

These examples only read existing documents. They do not modify the model or launch a simulation.

For larger models, follow snapshot.next_page_token with the same filters and expected_revision=snapshot.revision. That keeps each page tied to one model revision.

03

Construct and revise models

Build a ModelDraft from an inspected document version and model slice. Use typed builders to define materials, physics and Study settings, then review the proposed changes before applying them.

This excerpt from the cantilever recipe defines steel, a solid body and a linear-static Study. Here, draft is your ModelDraft and beam is the inspected geometry’s BodyRef.

Cantilever · model excerpt
from nsim.materials import IsotropicElastic

steel = draft.materials.add(
    key="steel",
    model=IsotropicElastic(210e9, 0.3, 7850),
)
solid = draft.fea.solid(
    key="beam-solid", geometry=beam, material=steel
)
study = draft.fea.linear_static(
    key="bending",
    bodies=[solid],
    participant_id="structure",
    solver_family="code-aster",
)
study.mesh(element_size=(10, "mm"))
Python

Inputs accept SI numbers or explicit unit tuples, such as (10, "mm"). The complete recipe adds a fixed root, a tip force and resource settings.

  1. Plan. Capture the draft with draft.plan().
  2. Review. Call document.prepare(plan) and inspect its changes and diagnostics.
  3. Apply. Pass the reviewed object to document.commit(prepared, request_id=...), retaining a unique request ID for recovery.

Recipe and entity keys identify the fields your script manages. An unchanged rerun is a no-op; a conflicting human edit is reported for review.

From a model to a run

Validate the exact Study, build and select its mesh when required, then freeze the inputs and submit the simulation. The SDK’s client.meshes and client.runs interfaces expose these explicit steps. Discover the available contracts with client.capabilities.list().

04

Read saved results

Start by discovering the datasets published for your document. Each reference identifies a saved result, including its generation and content hash.

result_fields.py
import os
from nsim import Client

with Client.from_env() as client:
    datasets = client.results.list_datasets(
        document_id=os.environ["NSIM_DOCUMENT_ID"],
        page_size=10,
    )
    for dataset in datasets.items:
        fields = client.results.list_fields(
            dataset.reference, page_size=20
        )
        for field in fields.items:
            print(field.quantity, field.units)
Python

This reads the first page of datasets and fields. Follow each page’s next_page_token when more are available. Field metadata describes the quantity, units, components, frame and supported query methods.

Next stepPython operation
Exact result detailsclient.results.get_dataset(dataset.reference)
Saved sample timesclient.results.list_samples(...)
Review an analysisclient.results.preview(query)
Run the analysisclient.results.submit(query, request_id=...)

Supported analysis includes scalar reductions, discovered vector magnitudes, published boundary reductions and supported CFD point or line probes. Build queries from the discovered fields and methods, with explicit samples and resource budgets.

05

Explore the reference recipes

The developer source includes complete examples with units, engineering assumptions and retained request identities. Start from a new document when trying a construction recipe.

FEA

Cantilever

examples/cantilever.py imports a STEP bar, defines steel, fixes the root and applies a tip load. Rerun it to revise the managed force.

MULTIBODY

Rigid mechanism

examples/rigid_mechanism.py constructs a mechanism with rigid bodies, frames, a revolute joint and a point load.

FLOW

Laminar channel

examples/laminar_channel.py prepares a fluid region and defines inlet, outlet and wall conditions for steady laminar flow.

ITERATION

Excavator cycle timing

examples/excavator_timing.py revises an existing cycle’s command durations, runs candidates and compares saved checks to retain the fastest passing candidate tested.

The first three recipes construct models and Study settings; mesh generation and solving are separate operations. The timing example includes execution and requires an existing compatible model.

To give an AI agent access to these same engineering contracts, continue with the MCP guide.

Your next step

Build with your own models.

Get access to nsim and the developer setup for your team.

Request access