TL;DR Python Client Library
By
Susannah Brodnitz /
Product, Use Cases, Developer
Aug 09, 2022
Navigate to:
InfluxDB has over a dozen different client libraries to help developers work with time series data in whatever programming language they like best. The Python client library is one of our most popular options. It’s simple to learn, and working with InfluxDB in a language you’re comfortable with helps you get started doing powerful time series analysis quickly.
Batching data
Batching data lets you write your data to InfluxDB more efficiently, by sending thousands of data points at once. To do this you instantiate the write API class and set the batch size, along with other parameters like the flush interval and maximum number of retries. You can send data to InfluxDB in several different formats, including line protocol, point data structure, and Pandas DataFrames. This is meant to make it simple to send your data to InfluxDB regardless of the format.
Querying data
To query data from InfluxDB using the Python client library, you use the query API. The queries themselves are in Flux, which is housed within your Python code. This lets you return the data directly to your application, ready to use. You can return data in several different formats, including strings, CSVs, streams, and Pandas DataFrames. You start by instantiating the query class. There are a few different query functions you can choose from to return data in the format you want, and for each function you pass in a Flux query. The function query() returns Flux table structure; query_raw() returns an unformatted string; query_csv() returns a CSV file; query_data_frame() returns a Pandas DataFrame; and query_stream() returns a stream of data you can iterate through.
Administrative APIs
The Python client library can also do administrative management tasks, like creating organizations, buckets, and authorization tokens. You can also do these tasks through the InfluxDB UI, and that’s commonly how new InfluxDB users do things. But as you become more experienced and want to use InfluxDB in more advanced ways, you might want to create multiple instances of InfluxDB. The administrative API lets you automate this process instead of creating each instance manually in the UI. To work with the administrative API, you first instantiate the class you want to work with — organization, buckets, or authorization. Each class has functions that let you take actions, such as create_organization() and delete_bucket(). The delete API lets you delete records from InfluxDB.
You can watch our three-part video series on the Python client library to learn more.
Part One goes over batching data.
Part Two shows how to query data.
Part Three goes into the administrative tasks.