> ## Documentation Index
> Fetch the complete documentation index at: https://docs.speckle.systems/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> These docs describe Speckle as it works today, including everything released in 2026.9. Treat page content as current unless the page or section says it applies only to versions published before 2026.9.
> Content scoped to versions published before 2026.9 (the object graph and root object, Proxies, Receive2, operations.receive, object.children) applies only to model versions in that earlier data format. For versions published in 2026.9, answer from the Object model pages and the SDK migration guides.
> The What's new pages summarise what changed in 2026.9 and link to the page that documents each change. Answer from the linked page rather than from the summary. Legacy (v2) connectors are retired; send questions about them to the community help forum.
> Match guidance to the customer's deployment, model data format, connector, plan and permissions. Self-hosted servers on a release before 2026.9 and compatibility-mode workflows follow the Compatibility mode page. If an unknown version or data format changes the answer, ask one focused question; do not infer the deployment version from the date alone.

# Automate with scripts and notebooks

> Copy-paste bootstrap and Receive3 for console apps, Grasshopper C#, and notebooks — no DI tutorial required

## Goal

Get a working SpeckleSharp script with the shortest path to load and analyse model data — without learning dependency injection.

## What you will build

A script that authenticates, loads the latest version of an existing model, counts elements by category, and prints a summary to the console.

## When to use this

Use this page when you write:

* A one-off C# script or console app
* A Grasshopper **C# Script** or custom component
* A C# cell in a **polyglot notebook** (Jupyter, Visual Studio, Rider)
* A small automation that is **not** a desktop connector

You do **not** need to understand dependency injection, service lifetimes, or ASP.NET Core. Paste the bootstrap once, then write normal C# against `client`, `operations`, and the `Model` you receive.

> [!NOTE]
>
> If you are building a production desktop connector (Revit, Rhino, AutoCAD, and similar), start
> with [Dependency injection (connectors)](https://docs.speckle.systems/developers/sdks/dotnet/concepts/dependency-injection.md)
> and [Publish large models
> (connectors)](https://docs.speckle.systems/developers/sdks/dotnet/guides/building-connector-scale-sends.md) instead.

## Recommended approach

**Load model data with `Receive3`.** Paste the bootstrap below, authenticate with a PAT from `SPECKLE_TOKEN`, and call `IOperations.Receive3`. It returns a `Model`: a flat list of objects with path-keyed properties and relation accessors such as `Level` and `Host`.

Install a 2026.9 build of the SDK. 2026.9.0-beta.7 is the current one; a later stable 2026.9.0 replaces the pin without changing the code:

```bash theme={null}
dotnet add package Speckle.Sdk --version 2026.9.0-beta.7
```

> [!NOTE]
>
> Updating a script that uses `Receive2` and `Flatten()`? See [Migrate to
> 2026.9](https://docs.speckle.systems/developers/sdks/dotnet/migrate-to-2026-9.md) for each change side by side.

For Grasshopper object construction without server calls, see [Use SpeckleSharp in a Grasshopper C# node](https://docs.speckle.systems/developers/sdks/dotnet/guides/use-speckle-sdk-in-grasshopper-csharp.md). For connector Publish/Load on the canvas, use the Grasshopper connector — the SDK complements those components; it does not replace them.

## One-time bootstrap (copy this)

Paste this at the top of your script, notebook cell, or Grasshopper C# component. Run it once per process. This is the **canonical bootstrap** — other pages link here instead of repeating the full block.

```csharp Example lines icon="https://mintcdn.com/speckle/VtRPWzmN-ULoLfIv/images/developers/sdks/csharp.svg?fit=max&auto=format&n=VtRPWzmN-ULoLfIv&q=85&s=f2970e3b8bd4a2c7899b46211a42f251" theme={null}
using Microsoft.Extensions.DependencyInjection;
using Speckle.Sdk;
using Speckle.Sdk.Api;
using Speckle.Sdk.Credentials;

static class SpeckleBootstrap
{
    static readonly ServiceProvider Provider = new ServiceCollection()
        .AddSpeckleSdk(
            new Application("My Script", "my-script"),
            "1.0.0",
            typeof(Speckle.Objects.Geometry.Point).Assembly
        )
        .BuildServiceProvider();

    public static IOperations Operations => Provider.GetRequiredService<IOperations>();
    public static IAccountFactory AccountFactory => Provider.GetRequiredService<IAccountFactory>();
    public static IClientFactory ClientFactory => Provider.GetRequiredService<IClientFactory>();
}
```

> [!TIP]
>
> You can rename `SpeckleBootstrap` to anything. The point is a single static holder so notebook
> cells and script functions do not repeat `new ServiceCollection()` on every run.

> [!WARNING]
>
> There is no `new Operations()` or import-and-go equivalent. Every public entry point
> (`IOperations`, `IClientFactory`, `IAccountFactory`) is resolved from the bootstrap container.
> That is a one-time setup cost, not an ongoing architectural commitment.

## Complete example

Load an existing model and count elements by category:

```csharp Complete example lines icon="https://mintcdn.com/speckle/VtRPWzmN-ULoLfIv/images/developers/sdks/csharp.svg?fit=max&auto=format&n=VtRPWzmN-ULoLfIv&q=85&s=f2970e3b8bd4a2c7899b46211a42f251" expandable theme={null}
var token = Environment.GetEnvironmentVariable("SPECKLE_TOKEN")
    ?? throw new InvalidOperationException("Set SPECKLE_TOKEN");
var projectId = Environment.GetEnvironmentVariable("SPECKLE_PROJECT_ID")
    ?? throw new InvalidOperationException("Set SPECKLE_PROJECT_ID");
var modelId = Environment.GetEnvironmentVariable("SPECKLE_MODEL_ID")
    ?? throw new InvalidOperationException("Set SPECKLE_MODEL_ID");

var account = await SpeckleBootstrap.AccountFactory.CreateAccount(
    new Uri(Environment.GetEnvironmentVariable("SPECKLE_SERVER") ?? "https://app.speckle.systems"),
    token
);
using var client = SpeckleBootstrap.ClientFactory.Create(account);

var versions = await client.Version.GetVersions(modelId, projectId, limit: 1);
var latest = versions.items.FirstOrDefault()
    ?? throw new InvalidOperationException("No versions on this model");

using var model = await SpeckleBootstrap.Operations.Receive3(
    account,
    projectId,
    modelId,
    latest.id,
    options: null,
    cancellationToken: default
);

var counts = model.Objects
    .GroupBy(o => o.GetString("category") ?? o.Name ?? "Unknown")
    .OrderByDescending(g => g.Count());

Console.WriteLine($"Model: {latest.message} — {model.Objects.Count} objects");
foreach (var group in counts.Take(15))
    Console.WriteLine($"  {group.Key}: {group.Count()}");
```

You should see the version message, the object count, and up to 15 categories with their counts.

> [!NOTE]
>
> `options` and `cancellationToken` are for long-running host applications (connectors with progress
> UI and cancel buttons). For scripts, `null` and `default` are correct — not placeholders to
> replace.

> [!TIP]
>
> `Receive3` also takes the model URL you copy from the web app: `Receive3(account, new
>     Uri(modelUrl), options: null, cancellationToken: default)`. Without `@versionId` in the URL it
> loads the latest version.

## How it works

| What you want | Resolve from bootstrap | Then use |
| - | - | - |
| GraphQL API (`Project`, `Model`, `Version`, …) | `IClientFactory` → `Create(account)` | `client.Version.GetVersions(...)`, `client.Project.Get(...)` |
| Load or publish model data | `IOperations` | `Receive3`, `Send3` |
| Build an account from a PAT | `IAccountFactory` | `CreateAccount(serverUrl, token)` |
| Reuse a desktop login | `IAccountManager` (optional) | `GetAccounts()`, `GetDefaultAccount()` |

`Receive3` returns a `Model`. Query it with `model.Objects`, `model.ObjectsWith("path")`, and `model.ObjectByApplicationId(id)`. Read properties with dotted paths (`obj.GetDouble("Constraints.Base Offset")`) and follow relations with accessors (`obj.Level`, `obj.Host`, `obj.Material`). See [Object model](https://docs.speckle.systems/developers/object-model/overview.md) for how the data is shaped, and [Load and publish model data](https://docs.speckle.systems/developers/sdks/dotnet/concepts/send-and-receive-paths.md) for the other paths.

## Common mistakes

| Mistake | Fix |
| - | - |
| Creating a new `ServiceProvider` on every notebook cell run | Define the static bootstrap once per session |
| Installing `Speckle.Sdk` without a version | You get 2026.8, which has no `Receive3`. Reinstall with `--version 2026.9.0-beta.7` |
| Calling `Receive3` without `using` | The downloaded bundle files stay on disk. Write `using var model = …` |
| `Receive3` throws because the version has no bundle | The version was published before 2026.9 and not converted. Load it with `Receive2` |
| Walking `Flatten()` or proxy lists on 2026.9 data | Query `model.Objects` and relation accessors — see [Relations](https://docs.speckle.systems/developers/object-model/relations.md) |

## What to skip (unless you are building a connector)

| Page / topic | Why scripts can skip it |
| - | - |
| [Dependency injection (connectors)](https://docs.speckle.systems/developers/sdks/dotnet/concepts/dependency-injection.md) | Deep dive for host apps sharing a container |
| [Publish large models (connectors)](https://docs.speckle.systems/developers/sdks/dotnet/guides/building-connector-scale-sends.md) | `SendPipeline` — production connector upload only |
| [Working with Proxies](https://docs.speckle.systems/developers/sdks/dotnet/guides/working-with-proxies.md) | Only for versions published before 2026.9 |

## Grasshopper and hosted scripts

**Speckle connector components** (Publish, Load): use the components for transport.

**Custom analysis in Grasshopper C#:** see [Use SpeckleSharp in a Grasshopper C# node](https://docs.speckle.systems/developers/sdks/dotnet/guides/use-speckle-sdk-in-grasshopper-csharp.md) for object construction; return here for `Receive3`.

## Polyglot notebooks

1. Paste the bootstrap in the **first** cell and run it once per kernel session.
2. In later cells, call `SpeckleBootstrap.Operations`, `SpeckleBootstrap.ClientFactory`, and so on directly.
3. Store `account`, `client`, or `model` in notebook variables if you reuse them — `IClient` and `Model` are `IDisposable`.

## Next Steps

> [card] [Build your first model analysis tool](https://docs.speckle.systems/developers/sdks/dotnet/guides/build-your-first-model-analysis-tool.md)
>
> Full CSV report walkthrough

> [card] [Authentication](https://docs.speckle.systems/developers/sdks/dotnet/getting-started/authentication.md)
>
> PAT and environment variables

> [card] [Migrate to 2026.9](https://docs.speckle.systems/developers/sdks/dotnet/migrate-to-2026-9.md)
>
> Move a Receive2 script to Receive3

## FAQ

> [accordion] Do I have to learn Microsoft.Extensions.DependencyInjection?
>
> No. Treat `AddSpeckleSdk` + `BuildServiceProvider()` as a required preamble — like adding
> `using` statements.

> [accordion] Which quickstart should I follow?
>
> [Build your first model analysis
> tool](https://docs.speckle.systems/developers/sdks/dotnet/guides/build-your-first-model-analysis-tool.md) for a complete
> automation. This page for the bootstrap snippet. [Publish and load a model from
> C#](https://docs.speckle.systems/developers/sdks/dotnet/getting-started/quickstart.md) if you want to publish your own data
> from scratch.

> [accordion] What if the model was published before 2026.9?
>
> `Receive3` loads it when the server holds that version in the 2026.9 format. If it throws
> because the version has no bundle, load it with `Receive2`. See [Read versions published before
> 2026.9](https://docs.speckle.systems/developers/sdks/dotnet/migrate-to-2026-9.md#read-versions-published-before-2026-9).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.