# Python script to export tags every 2 seconds

**URL:** <https://forum.inductiveautomation.com/t/python-script-to-export-tags-every-2-seconds/56144>\
**Category:** Ignition\
**Tags:** ignition80, scripting\
**Created:** [February 15, 2022, 1:27am UTC](https://forum.inductiveautomation.com/t/python-script-to-export-tags-every-2-seconds/56144 "2022-02-15T01:27:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![MOISES\_SALAZAR](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@MOISES\_SALAZAR](https://forum.inductiveautomation.com/u/MOISES_SALAZAR)\
**Post date:** [February 15, 2022, 1:27am UTC](https://forum.inductiveautomation.com/t/python-script-to-export-tags-every-2-seconds/56144/1 "2022-02-15T01:27:20Z")

</div>

Need to export a PLC tags every 2 seconds on JSON format. I need a good solution, any help will be appreciated.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [February 15, 2022, 1:49am UTC](https://forum.inductiveautomation.com/t/python-script-to-export-tags-every-2-seconds/56144/2 "2022-02-15T01:49:38Z")

</div>

A gateway timer ~~or schedule~~ script using system.tag.exportTags should do it. I think the default type is JSON, if not you can set it to JSON.  
[system.tag.exportTags](https://docs.inductiveautomation.com/display/DOC81/system.tag.exportTags)

Welcome to the forum!

---

<div class="post-metadata">

**Author:** ![Bryan\_Mason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bryan_mason/32/30612_2.png) [@Bryan\_Mason](https://forum.inductiveautomation.com/u/Bryan_Mason)\
**Post date:** [February 17, 2022, 7:56pm UTC](https://forum.inductiveautomation.com/t/python-script-to-export-tags-every-2-seconds/56144/3 "2022-02-17T19:56:27Z")

</div>

Moisis, you probably want to export the tag _values_, right? system.tag.exportTags will only export the definitions. You can use [system.tag.browse](https://docs.inductiveautomation.com/display/DOC81/system.tag.browse) to access the value.

Then you can do some python magic to export to a JSON file. I tried but the object isn’t JSON serializable. I created another script that exports to a CSV file so I can backup and restore tag values. Is the JSON format important to you?

---

<div class="post-metadata">

**Author:** ![MOISES\_SALAZAR](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@MOISES\_SALAZAR](https://forum.inductiveautomation.com/u/MOISES_SALAZAR)\
**Post date:** [February 17, 2022, 8:20pm UTC](https://forum.inductiveautomation.com/t/python-script-to-export-tags-every-2-seconds/56144/4 "2022-02-17T20:20:32Z")

</div>

Yes, it is and as you said I need to use system.tag.browse and convert everything to python dict and then to json after that another script takes care of the “snapshot” files make it serializable and wrapping them for the data feed.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 17, 2022, 8:22pm UTC](https://forum.inductiveautomation.com/t/python-script-to-export-tags-every-2-seconds/56144/5 "2022-02-17T20:22:59Z")

</div>

Are you sure you want to be _exporting_ the tags every 2 seconds? Exports are for configuration, not just the values, and this is going to be a performance nightmare…

At that interval I can only assume what you’re really interested in are the tag values, which you should just be reading with `system.tag.readBlocking` instead.

---

<div class="post-metadata">

**Author:** ![MOISES\_SALAZAR](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@MOISES\_SALAZAR](https://forum.inductiveautomation.com/u/MOISES_SALAZAR)\
**Post date:** [February 17, 2022, 8:55pm UTC](https://forum.inductiveautomation.com/t/python-script-to-export-tags-every-2-seconds/56144/6 "2022-02-17T20:55:55Z")

</div>

well, I’m exporting the tags but only interested in the following fields:  
-name  
-Value  
-t\_stamps  
-quality  
There is a scripts which deletes all old files to avoid running out of storage but, how can I improved the performance of this task?

---

<div class="post-metadata">

**Author:** ![thecesrom.git](https://avatars.discourse-cdn.com/v4/letter/t/dfb087/32.png) [@thecesrom.git](https://forum.inductiveautomation.com/u/thecesrom.git)\
**Post date:** [February 17, 2022, 10:09pm UTC](https://forum.inductiveautomation.com/t/python-script-to-export-tags-every-2-seconds/56144/7 "2022-02-17T22:09:03Z")

</div>

What about enabling Tag History and store data every two seconds?

[https://docs.inductiveautomation.com/display/DOC81/Configuring+Tag+History](https://docs.inductiveautomation.com/display/DOC81/Configuring+Tag+History)

---

<div class="post-metadata">

**Author:** ![MOISES\_SALAZAR](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@MOISES\_SALAZAR](https://forum.inductiveautomation.com/u/MOISES_SALAZAR)\
**Post date:** [February 17, 2022, 11:31pm UTC](https://forum.inductiveautomation.com/t/python-script-to-export-tags-every-2-seconds/56144/8 "2022-02-17T23:31:09Z")

</div>

but then how I will feed the data to the uploading application? it must be in json format for the application to be able to transfer the data.

---

<div class="post-metadata">

**Author:** ![thecesrom.git](https://avatars.discourse-cdn.com/v4/letter/t/dfb087/32.png) [@thecesrom.git](https://forum.inductiveautomation.com/u/thecesrom.git)\
**Post date:** [February 17, 2022, 11:46pm UTC](https://forum.inductiveautomation.com/t/python-script-to-export-tags-every-2-seconds/56144/9 "2022-02-17T23:46:46Z")

</div>

Perhaps [`incendium.dataset.to_json`](https://github.com/thecesrom/incendium/wiki/incendium.dataset.to_json) might help you.

> **[Ignition Exchange](https://inductiveautomation.com/exchange/2104/)**
>
> Discover, share, and download community made Ignition resources in collaboration with your organization or the Ignition community.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 18, 2022, 11:07am UTC](https://forum.inductiveautomation.com/t/python-script-to-export-tags-every-2-seconds/56144/10 "2022-02-18T11:07:20Z")

</div>

If you know the names of your tags, I’d recommend making a list and using system.tag.readBlocking().

If not, I’d recommend a separate script to construct the tag names and either store them in the db or into a dataset memory tag. This one wouldn’t have to run as often, as they shouldn’t change often.  
readBlocking would still read your qualified tag values.

---

<div class="post-metadata">

**Author:** ![gnguyen](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@gnguyen](https://forum.inductiveautomation.com/u/gnguyen)\
**Post date:** [February 18, 2022, 1:11pm UTC](https://forum.inductiveautomation.com/t/python-script-to-export-tags-every-2-seconds/56144/11 "2022-02-18T13:11:54Z")

</div>

Or transaction group
