openHistorian API


I am new with openPDC and found that we can use the openhistorian python API to fetch data. I want to use the fetched data to be saved into readable csv file. I would kindly request some help how to do it.

I am aware that I can go to the web browser app for openhistorian to export data as csv, but wanted to check if we can do it via python.

Hi bhaskarmitra,

The openhistorian-python project has example code you can use to read data from openHistorian. I would be surprised if it couldn’t be readily adapted to write a CSV file.

Can you be more specific about what kind of help you need?


Hi Stephen, Thanks for your response. I want to connect to the running openhistorian through python and then once data archiving is complete, want to export it as readable csv. Something similar that we can do though the localhost page using chrome (not sure what is it exactly called), please see screenshot…

I believe I understand what you are trying to do, but I don’t understand what you need help with. Currently, I don’t know any details about what you have set up and where you’ve gotten stuck. At a high level, you’ll need to do the following things.

  • Install openHistorian
  • Connect openHistorian to a streaming data source and start archiving
  • Run the sample code from the openhistorian-python project
  • Modify the sample code to produce a CSV file

Thanks Stephen I shall follow the steps, I am in the process of writing the code.


I did run the sample code, but it returns zero data points.

I have some data archived in my archive folder by running openhistorian.

Please note there was no instance of openhistorian running when I was running the python script.

Kindly requesting you assistance;



Looks like data read was for 2022-04-07, but your data in file list only goes up to 2022-04-06.

Thanks Ritchie, is there a way I can customize the date range when I try to read the data?

The sample code has these lines that determine the start time and end time of the query.

# Execute a test read for data archived ten seconds ago
endTime = datetime.utcnow() - timedelta(seconds = 10)
startTime = endTime - timedelta(milliseconds = 33)

I changed the sample code but it still returns null,

Based on your previous screenshot of the stage1 files in your archive, there is a gap between April 2 and April 6, so you probably aren’t going to have any data on April 5. Try to line up the timestamps in your sample code with the timestamps on your archive’s file names. I would recommend trying 2022-04-06 00:58 through 2022-04-06 01:04.

1 Like

Yes thanks Stephen I found my mistake, I was making my query based on the date modified and not the date printed on the file name. Thank you so much to you and Ritchie for the constant guidance and help. :slight_smile: