---
id: "M:cAlgo.API.LocalStorage.GetObject``1(System.String)"
kind: "method"
type: "T:cAlgo.API.LocalStorage"
url: "https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/GetObject/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# LocalStorage.GetObject

Member of [LocalStorage](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/index.md).

## GetObject(string key)

Gets an object from local storage. This method will search all available scopes (Instance -&gt; Type -&gt; Device) and stops on first found value.

Environments: Desktop supported · CLI supported · Cloud works differently.

- Cloud: Key not set in this run returns default and sends LocalStorageException 'Getting local storage data from file is not supported in cloud environment.' to OnException.

C#:

```csharp
T GetObject(string key)
```

Python:

```python
api.LocalStorage.GetObject(key: str) -> T
```

### Parameters

- `key` (`string`, Python `str`): The key of the element to get, max length for keys is 50 characters, and only alphanumeric and space characters are allowed, you can only use space in the middle of key not at the start or end

### Returns

`T` — The deserialized object or default value of type if the provided key is not found or the object cannot be deserialized

### Examples

C#:

```csharp
LocalStorage.SetObject("Trades Count", 5);
var tradesCount = LocalStorage.GetObject<int>("Trades Count");
Print("Trades count: {0}", tradesCount);
```

Python:

```python
from System import Int32

api.LocalStorage.SetObject("Trades Count", 5)
tradesCount = api.LocalStorage.GetObject[Int32]("Trades Count")
api.Print(f"Trades count: {tradesCount}")
```

## GetObject(string key, LocalStorageScope localStorageScope)

Gets an object from local storage.

Environments: Desktop supported · CLI supported · Cloud works differently.

- Cloud: Key not set in this run returns default and sends LocalStorageException 'Getting local storage data from file is not supported in cloud environment.' to OnException.

C#:

```csharp
T GetObject(string key, LocalStorageScope localStorageScope)
```

Python:

```python
api.LocalStorage.GetObject(key: str, localStorageScope: LocalStorageScope) -> T
```

### Parameters

- `key` (`string`, Python `str`): The key of the element to get, max length for keys is 50 characters, and only alphanumeric and space characters are allowed, you can only use space in the middle of key not at the start or end
- `localStorageScope` (`LocalStorageScope`, Python `LocalStorageScope`): The storage scope of the element

### Returns

`T` — The deserialized object or default value of type if the provided key is not found or the object cannot be deserialized

### Examples

C#:

```csharp
LocalStorage.SetObject("Trades Count", 5, LocalStorageScope.Type);
var tradesCount = LocalStorage.GetObject<int>("Trades Count", LocalStorageScope.Type);
Print("Trades count across instances: {0}", tradesCount);
```

Python:

```python
from System import Int32

api.LocalStorage.SetObject("Trades Count", 5, LocalStorageScope.Type)
tradesCount = api.LocalStorage.GetObject[Int32]("Trades Count", LocalStorageScope.Type)
api.Print(f"Trades count across instances: {tradesCount}")
```

