# Gateway History Provider: Method to get list of History Providers from Gateway

**URL:** <https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [June 19, 2023, 2:01am UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191 "2023-06-19T02:01:48Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![mudbay](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@mudbay](https://forum.inductiveautomation.com/u/mudbay)\
**Post date:** [June 19, 2023, 2:01am UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/1 "2023-06-19T02:01:48Z")

</div>

Wondering if anyone knows how to access the list of History Provider names from the Gateway using scripts. I can't seem to be able to find a method to do this. (Tried this method ' 'system.db.getConnections()' but this gives you the Gateway/Config/Database/Connections list)

I Designer it is found under Tag Properties:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/3/439b43c0ffba8b417aad604f0f251ec08b7a1e63.png)

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [June 20, 2023, 12:32pm UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/2 "2023-06-20T12:32:59Z")

</div>

In my test environment, this approach seemed to work:

```auto
tagBrowseResults = system.tag.browseHistoricalTags().results
historyProviders = [str(result.path.lastPathComponent) for result in tagBrowseResults]
print historyProviders

```

**Output:**

```auto
['Sample_SQLite_Database']

```

Tag provider list:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/9/b9c7d943bf528c11e3b1727eaaf36057f48fda54.png)

---

<div class="post-metadata">

**Author:** ![mudbay](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@mudbay](https://forum.inductiveautomation.com/u/mudbay)\
**Post date:** [June 20, 2023, 2:01pm UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/3 "2023-06-20T14:01:07Z")

</div>

Love it! Thanks.

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [June 20, 2023, 2:42pm UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/4 "2023-06-20T14:42:50Z")

</div>

Is there a way to filter the historical providers to return only the ones that are enabled? I have a project that needs this list, but it'll also return the historical tag providers of database connection that are disabled, which is not preferable since I'll use the value they select in a `storeTagHistory` function call.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [June 22, 2023, 5:36am UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/5 "2023-06-22T05:36:21Z")

</div>

> [@YF129701](#):
>
> but it'll also return the historical tag providers of database connection that are disabled

I feel kinda silly at the moment; I took this at face value without validating it. The method I posted above **does not** return the database if it is not enabled:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/7/874ac188378999e82b9450b1aa9823d440b403d4.png)

Using the script from **[post 2](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/2)**, this is the output:

```auto
['Sample_SQLite_Database', 'Test History Provider 2']

```

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [June 22, 2023, 5:52am UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/6 "2023-06-22T05:52:23Z")

</div>

Thank you for developing this just for me 🥰. What I ended up doing in the meantime is to retrieve the "Valid" database connections, since they correspond to historical tag providers (?). This didn't seem right to me as there might be instances where the list of database connections and historical tag providers will not match exactly, so I would run into problems then.

Are there obvious cases where this would happen?

Here is the script I got from a smart coworker:

```auto
for row in system.dataset.toPyDataSet(system.db.getConnections()):
    if row[3] == "Valid":
        ... # put work here

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [June 22, 2023, 6:13am UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/7 "2023-06-22T06:13:35Z")

</div>

> [@mudbay](#):
>
> Tried this method ' 'system.db.getConnections()' but this

Since the OP had explicitly stated that this approach was not applicable to this usage case, I intentionally didn't go there. Instead, I looked for functions and methods that were specific to tag history. When I couldn't find anything in the system functions for determining enabledness, I started digging around in the gateway looking specifically for the enabled bool, but I never found it. Instead, as I was looking for it, one of my experiments yielded the expected result, so I decided to call it a night and post it. **Edit:** but then it occurred to me that a disabled provider shouldn't be showing up in a tag browse, so I did a quick test and discovered that it did not return disabled tag history providers.

Oops! I spent time trying to fix a problem that didn't exist. lol

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [June 22, 2023, 1:54pm UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/8 "2023-06-22T13:54:20Z")

</div>

This isn't for a Tag Browse component - I'm adding the historical tag providers to a dropdown for selection.

That's right, I forgot about OP mentioning using `getConnections()`.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 22, 2023, 3:48pm UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/9 "2023-06-22T15:48:44Z")

</div>

The ~~'proper'~~ way to do this is to go from a `GatewayContext` instance to the `HistoryManager`, then use the [`getStores(HistoryFlavor)`](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.27/com/inductiveautomation/ignition/gateway/history/HistoryManager.html#getStores(com.inductiveautomation.ignition.gateway.history.HistoryFlavor)) method (using the static [`SQLTAG`](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.27/com/inductiveautomation/ignition/gateway/history/HistoryFlavor.html#SQLTAG) `HistoryFlavor`).

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 22, 2023, 4:10pm UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/10 "2023-06-22T16:10:55Z")

</div>

> [@paul-griffith](#):
>
> The 'proper' way to do this is to go from a `GatewayContext` instance

Wait! What?

Since when is using a `GatewayContext` anything but utterly unsupported?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 22, 2023, 4:14pm UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/11 "2023-06-22T16:14:06Z")

</div>

Well, okay, proper is a strong word. The _only_ way to do it, and get an answer that will be right 100% of the time, is the method I described. An ideas post would be good for a scripting function or something, if this is a common thing folks need.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 22, 2023, 4:49pm UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/12 "2023-06-22T16:49:36Z")

</div>

> [@paul-griffith](#):
>
> An ideas post would be good for a scripting function or something, if this is a common thing folks need

How about an addition into Ignition Extensions?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 22, 2023, 5:16pm UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/13 "2023-06-22T17:16:40Z")

</div>

🤷‍♂️  
Current Ignition Extensions:

```python
from com.inductiveautomation.ignition.gateway.history import HistoryFlavor
stores = system.util.context.historyManager.getHistoryStores(HistoryFlavor.SQLTAG)

```

With a fancier scripting implementation:

```auto
stores = system.util.getHistoryProviders()

```

It doesn't feel worthwhile to add to Ignition Extensions where you've already got easy access to the local `context`. It would be more valuable first party, as a 'blessed' option.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [June 25, 2023, 3:12am UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/14 "2023-06-25T03:12:37Z")

</div>

I found some more time to play around with this again, and I'm calling the following lines of code in a library script with a gateway message handler via send request:

```auto
stores = context.historyManager.getStores(HistoryFlavor.SQLTAG)
return [str(stores[0]), dir(stores[0])]

```

> **Output:**
>
> ```auto
> ['Sample_SQLite_Database', [' __add__', ' __class__', ' __cmp__', ' __contains__', ' __delattr__', ' __doc__', ' __ensure_finalizer__', 
> ' __eq__', ' __format__', ' __ge__', ' __getattribute__', ' __getitem__', ' __getnewargs__', ' __getslice__', 
> ' __gt__', ' __hash__', ' __init__', ' __le__', ' __len__', ' __lt__', ' __mod__', ' __mul__', ' __ne__', 
> ' __new__', ' __reduce__', ' __reduce_ex__', ' __repr__', ' __rmul__', ' __setattr__', ' __str__', 
> ' __subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 
> 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdecimal', 
> 'isdigit', 'islower', 'isnumeric', 'isspace', 'istitle', 'isunicode', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 
> 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 
> 'swapcase', 'title', 'translate', 'upper', 'zfill']]
> 
> ```

It doesn't return the database when the database is disabled, and I still don't see the enabled bit I was looking for, so I must have missed a key concept. What is the advantage of this approach over `system.tag.browseHistoricalTags().results`? Is it the fact that it doesn't return non SQL historical tag provider types?

---

<div class="post-metadata">

**Author:** ![David\_Gillbee](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@David\_Gillbee](https://forum.inductiveautomation.com/u/David_Gillbee)\
**Post date:** [August 2, 2024, 4:56am UTC](https://forum.inductiveautomation.com/t/gateway-history-provider-method-to-get-list-of-history-providers-from-gateway/75191/15 "2024-08-02T04:56:52Z")

</div>

The standard Ignition function [`system.tag.browseHistoricalTags`](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-browseHistoricalTags) can be used to retrieve the list of Historical Providers.

The code i used is:  
`[a.path for a in system.tag.browseHistoricalTags('').getResults()]`

Given an empty path parameter the results are simply the top level histprov paths. You can then access the results and retrieve the path for each using a list comprehension.
