Skip to main content

Community Python client for InfluxDB 3.0

Project description

Your Image

PyPI version PyPI downloads Lint Code Base Lint Code Base Community Slack

InfluxDB 3.0 Python Client

Introduction

influxdb_client_3 is a Python module that provides a simple and convenient way to interact with InfluxDB 3.0. This module supports both writing data to InfluxDB and querying data using the Flight client, which allows you to execute SQL and InfluxQL queries on InfluxDB 3.0.

Dependencies

  • pyarrow
  • influxdb-client

These are installed as part of the package

Installation

You can install 'influxdb3-python' using pip:

pip install influxdb3-python

Note: Please make sure you are using 3.6 or above. For the best performance use 3.11+

Usage

Importing the Module

from influxdb_client_3 import InfluxDBClient3, Point

Initialization

If you are using InfluxDB Cloud, then you should note that:

  1. You will need to supply your org id, this is not necessary for InfluxDB Dedicated.
  2. Use a bucketname for the database argument.
client = InfluxDBClient3(token="your-token",
                         host="your-host",
                         org="your-org",
                         database="your-database")

Writing Data

You can write data using the Point class, or supplying line protocol.

Using Points

point = Point("measurement").tag("location", "london").field("temperature", 42)
client.write(point)

Using Line Protocol

point = "measurement fieldname=0"
client.write(point)

Write from file

Users can import data from CSV, JSON, Feather, ORC, Parquet

import influxdb_client_3 as InfluxDBClient3
import pandas as pd
import numpy as np
from influxdb_client_3 import write_client_options, WritePrecision, WriteOptions, InfluxDBError


class BatchingCallback(object):

    def success(self, conf, data: str):
        print(f"Written batch: {conf}, data: {data}")

    def error(self, conf, data: str, exception: InfluxDBError):
        print(f"Cannot write batch: {conf}, data: {data} due: {exception}")

    def retry(self, conf, data: str, exception: InfluxDBError):
        print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}")

callback = BatchingCallback()

write_options = WriteOptions(batch_size=500,
                                        flush_interval=10_000,
                                        jitter_interval=2_000,
                                        retry_interval=5_000,
                                        max_retries=5,
                                        max_retry_delay=30_000,
                                        exponential_base=2)

wco = write_client_options(success_callback=callback.success,
                          error_callback=callback.error,
                          retry_callback=callback.retry,
                          WriteOptions=write_options 
                        )

with  InfluxDBClient3.InfluxDBClient3(
    token="INSERT_TOKEN",
    host="eu-central-1-1.aws.cloud2.influxdata.com",
    org="6a841c0c08328fb1",
    database="python", write_client_options=wco) as client:


    client.write_file(
        file='./out.csv',
        timestamp_column='time', tag_columns=["provider", "machineID"])
    
    client.write_file(
        file='./out.json',
        timestamp_column='time', tag_columns=["provider", "machineID"], date_unit='ns' )
    

Querying

Querying with SQL

query = "select * from measurement"
reader = client.query(query=query, language="sql")
table = reader.read_all()
print(table.to_pandas().to_markdown())

Querying with influxql

query = "select * from measurement"
reader = client.query(query=query, language="influxql")
table = reader.read_all()
print(table.to_pandas().to_markdown())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

influxdb3-python-0.1.7.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

influxdb3_python-0.1.7-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file influxdb3-python-0.1.7.tar.gz.

File metadata

  • Download URL: influxdb3-python-0.1.7.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for influxdb3-python-0.1.7.tar.gz
Algorithm Hash digest
SHA256 b0084b0044930bb4b2b2eddb38044ecfe2093b7ee596d4f1db263782f3156320
MD5 3db14c1e191f2302792562c4ed3c4bd9
BLAKE2b-256 3b6b54b695a275f71c63fc542e4c48861cfed95f24753a6c1c2412e63057b17d

See more details on using hashes here.

File details

Details for the file influxdb3_python-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for influxdb3_python-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 432dff742ca092f6cae70210effd806aac833d9a5110fb2a9618066a332a58df
MD5 fcc96cc511b41f2fceeede5748f0f7d3
BLAKE2b-256 d25d8e4ff527b98ffb00d2972c98011f58ba7695966f40b0b60acdfd756cdd88

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page