InfluxDB client library for time series database operations with comprehensive API for data management and querying
—
Backward compatibility support for InfluxDB 0.8.x servers through dedicated client implementations. The influxdb08 module provides complete API compatibility with older InfluxDB versions, enabling migration and support for legacy deployments.
The legacy module is included within the main influxdb package and provides dedicated classes for InfluxDB 0.8.x compatibility.
from influxdb.influxdb08 import InfluxDBClient, DataFrameClient, SeriesHelperInfluxDB 0.8.x client with API methods specific to the older server version and data model.
class InfluxDBClient:
"""
InfluxDB client for 0.8.x servers with legacy API support.
Note: This client uses different method signatures and data formats
compared to the modern InfluxDBClient for 1.x+ servers.
"""
def __init__(self, host='localhost', port=8086, username='root', password='root',
database=None, ssl=False, verify_ssl=False, timeout=None, use_udp=False,
udp_port=4444):
"""
Initialize legacy InfluxDB client.
Parameters:
- host (str): Hostname (default: 'localhost')
- port (int): Port number (default: 8086)
- username (str): Username (default: 'root')
- password (str): Password (default: 'root')
- database (str): Database name (default: None)
- ssl (bool): Use SSL (default: False)
- verify_ssl (bool): Verify SSL certificates (default: False)
- timeout (int): Request timeout (default: None)
- use_udp (bool): Use UDP (default: False)
- udp_port (int): UDP port (default: 4444)
"""Database management operations specific to InfluxDB 0.8.x.
def create_database(self, database):
"""
Create a new database in InfluxDB 0.8.x.
Parameters:
- database (str): Database name to create
Returns:
bool: True if successful
Raises:
InfluxDBClientError: If database creation fails
"""
def delete_database(self, database):
"""
Delete a database in InfluxDB 0.8.x.
Parameters:
- database (str): Database name to delete
Returns:
bool: True if successful
Raises:
InfluxDBClientError: If database deletion fails
"""
def get_list_database(self):
"""
Get list of databases in InfluxDB 0.8.x format.
Returns:
list: List of database information dictionaries
Raises:
InfluxDBClientError: If unable to retrieve databases
"""Data querying and writing operations for InfluxDB 0.8.x data model.
def write_points(self, *args, **kwargs):
"""
Write data points to InfluxDB 0.8.x.
Note: Uses different data format and parameters compared to 1.x+ client.
Consult InfluxDB 0.8.x documentation for specific format requirements.
Returns:
bool: True if successful
Raises:
InfluxDBClientError: If write operation fails
"""
def query(self, query, params=None, expected_response_code=200, database=None,
raise_errors=True):
"""
Execute query against InfluxDB 0.8.x server.
Parameters:
- query (str): InfluxQL query for 0.8.x
- params (dict): Query parameters (default: None)
- expected_response_code (int): Expected HTTP status (default: 200)
- database (str): Database name override (default: None)
- raise_errors (bool): Raise exceptions on errors (default: True)
Returns:
Results in InfluxDB 0.8.x format
Raises:
InfluxDBClientError: If query fails
"""
def delete_points(self, name):
"""
Delete points from a series in InfluxDB 0.8.x.
Parameters:
- name (str): Series name to delete points from
Returns:
bool: True if successful
Raises:
InfluxDBClientError: If deletion fails
"""User and administrator management for InfluxDB 0.8.x.
def add_cluster_admin(self, username, password):
"""
Add cluster administrator in InfluxDB 0.8.x.
Parameters:
- username (str): Admin username
- password (str): Admin password
Returns:
bool: True if successful
Raises:
InfluxDBClientError: If admin creation fails
"""
def delete_cluster_admin(self, username):
"""
Delete cluster administrator in InfluxDB 0.8.x.
Parameters:
- username (str): Admin username to delete
Returns:
bool: True if successful
Raises:
InfluxDBClientError: If admin deletion fails
"""
def get_list_cluster_admins(self):
"""
Get list of cluster administrators in InfluxDB 0.8.x.
Returns:
list: List of cluster administrator information
Raises:
InfluxDBClientError: If unable to retrieve admin list
"""
def set_database_admin_privilege(self, username, database, is_admin):
"""
Set database administrator privileges in InfluxDB 0.8.x.
Parameters:
- username (str): Username to modify
- database (str): Database name
- is_admin (bool): Grant or revoke admin privileges
Returns:
bool: True if successful
Raises:
InfluxDBClientError: If privilege modification fails
"""Series operations specific to InfluxDB 0.8.x data model.
def get_list_series(self, database=None):
"""
Get list of series in InfluxDB 0.8.x format.
Parameters:
- database (str): Database name (default: current database)
Returns:
list: List of series in 0.8.x format
Raises:
InfluxDBClientError: If unable to retrieve series
"""
def delete_series(self, series):
"""
Delete a series in InfluxDB 0.8.x.
Parameters:
- series (str): Series name to delete
Returns:
bool: True if successful
Raises:
InfluxDBClientError: If series deletion fails
"""Scheduled operation management for InfluxDB 0.8.x.
def create_scheduled_delete(self, delete_at, series_name):
"""
Create scheduled delete operation in InfluxDB 0.8.x.
Parameters:
- delete_at (str): When to execute the deletion
- series_name (str): Series name to delete
Returns:
bool: True if successful
Raises:
InfluxDBClientError: If scheduled delete creation fails
"""
def get_list_scheduled_delete(self):
"""
Get list of scheduled delete operations in InfluxDB 0.8.x.
Returns:
list: List of scheduled deletion information
Raises:
InfluxDBClientError: If unable to retrieve scheduled operations
"""
def remove_scheduled_delete(self, delete_id):
"""
Remove scheduled delete operation in InfluxDB 0.8.x.
Parameters:
- delete_id (int): ID of scheduled delete to remove
Returns:
bool: True if successful
Raises:
InfluxDBClientError: If scheduled delete removal fails
"""DataFrame integration for InfluxDB 0.8.x with pandas support.
class DataFrameClient(InfluxDBClient):
"""
DataFrame client for InfluxDB 0.8.x with pandas integration.
Provides similar functionality to the modern DataFrameClient but
adapted for InfluxDB 0.8.x data formats and API.
"""
def write_points(self, dataframe, *args, **kwargs):
"""
Write pandas DataFrame to InfluxDB 0.8.x.
Note: Uses different parameters and data format compared to 1.x+ client.
Consult legacy documentation for specific usage.
Parameters:
- dataframe (pandas.DataFrame): Data to write
- *args, **kwargs: Legacy-specific parameters
Returns:
bool: True if successful
Raises:
InfluxDBClientError: If write fails
"""
def query(self, query, *args, **kwargs):
"""
Query InfluxDB 0.8.x and return results as DataFrame.
Parameters:
- query (str): InfluxQL query for 0.8.x
- *args, **kwargs: Legacy-specific parameters
Returns:
pandas.DataFrame: Query results
Raises:
InfluxDBClientError: If query fails
"""Bulk data operations helper for InfluxDB 0.8.x.
class SeriesHelper:
"""
Series helper for bulk data operations in InfluxDB 0.8.x.
Provides similar functionality to the modern SeriesHelper but
adapted for InfluxDB 0.8.x data model and API requirements.
"""
def __init__(self, series_name, columns, points=None):
"""
Initialize legacy SeriesHelper.
Parameters:
- series_name (str): Name of the series
- columns (list): Column names for the series
- points (list): Initial data points (default: None)
"""
def add_point(self, point):
"""
Add a data point to the series.
Parameters:
- point (list): Data point values matching column order
"""
def commit(self, client):
"""
Commit all data points using the provided client.
Parameters:
- client (InfluxDBClient): Legacy client instance
Returns:
bool: True if successful
Raises:
InfluxDBClientError: If commit fails
"""from influxdb.influxdb08 import InfluxDBClient
from influxdb.exceptions import InfluxDBClientError
# Connect to InfluxDB 0.8.x server
legacy_client = InfluxDBClient(
host='legacy-influxdb.example.com',
port=8086,
username='admin',
password='admin'
)
try:
# Create database
legacy_client.create_database('legacy_metrics')
# List databases
databases = legacy_client.get_list_database()
print("Available databases:", databases)
# Switch to database
legacy_client.switch_database('legacy_metrics')
# Write data (0.8.x format)
# Note: Actual data format differs from 1.x+
legacy_client.write_points([
# 0.8.x specific data format
])
# Query data
result = legacy_client.query('list series')
except InfluxDBClientError as e:
print(f"Legacy client error: {e}")# Admin operations for 0.8.x
try:
# Add cluster admin
legacy_client.add_cluster_admin('legacy_admin', 'admin_password')
# List cluster admins
admins = legacy_client.get_list_cluster_admins()
print("Cluster admins:", admins)
# Set database admin privileges
legacy_client.set_database_admin_privilege('user1', 'mydb', True)
# Clean up
legacy_client.delete_cluster_admin('old_admin')
except InfluxDBClientError as e:
print(f"Legacy admin operation failed: {e}")from influxdb.influxdb08 import DataFrameClient
import pandas as pd
# Legacy DataFrame client
legacy_df_client = DataFrameClient(
host='legacy-server.example.com',
database='legacy_data'
)
# Create DataFrame (adapt to 0.8.x requirements)
df = pd.DataFrame({
'time': pd.date_range('2023-09-07', periods=10, freq='1H'),
'value': range(10)
})
try:
# Write DataFrame (0.8.x format)
legacy_df_client.write_points(df, 'measurement_name')
# Query into DataFrame
result_df = legacy_df_client.query('select * from measurement_name')
print(result_df.head())
except Exception as e:
print(f"Legacy DataFrame operation failed: {e}")from influxdb.influxdb08 import SeriesHelper
# Create series helper for 0.8.x
series_helper = SeriesHelper(
series_name='cpu_metrics',
columns=['time', 'host', 'cpu_usage']
)
# Add data points
series_helper.add_point(['2023-09-07T07:18:24Z', 'server01', 75.5])
series_helper.add_point(['2023-09-07T07:19:24Z', 'server01', 78.2])
# Commit to database
try:
series_helper.commit(legacy_client)
print("Legacy series data committed successfully")
except InfluxDBClientError as e:
print(f"Legacy series commit failed: {e}")When migrating from legacy InfluxDB 0.8.x to modern versions:
# Legacy 0.8.x client
from influxdb.influxdb08 import InfluxDBClient as LegacyClient
# Modern 1.x+ client
from influxdb import InfluxDBClient as ModernClient
def migrate_data(legacy_host, modern_host, database):
"""Example migration helper."""
# Connect to both versions
legacy = LegacyClient(host=legacy_host, database=database)
modern = ModernClient(host=modern_host)
# Create database in modern InfluxDB
modern.create_database(database)
modern.switch_database(database)
try:
# Get data from legacy system
legacy_series = legacy.get_list_series()
for series in legacy_series:
# Query legacy data
legacy_data = legacy.query(f'select * from {series}')
# Transform data format (0.8.x to 1.x+)
modern_points = transform_legacy_data(legacy_data)
# Write to modern InfluxDB
modern.write_points(modern_points)
print(f"Migration completed for database: {database}")
except Exception as e:
print(f"Migration failed: {e}")
def transform_legacy_data(legacy_data):
"""Transform 0.8.x data format to 1.x+ format."""
# Implementation depends on specific data structure differences
# between 0.8.x and 1.x+ formats
modern_points = []
# Transform each legacy data point
for point in legacy_data:
modern_point = {
"measurement": point.get('series_name'),
"tags": extract_tags_from_legacy(point),
"fields": extract_fields_from_legacy(point),
"time": point.get('time')
}
modern_points.append(modern_point)
return modern_points
# Execute migration
migrate_data('legacy.example.com', 'modern.example.com', 'metrics')Install with Tessl CLI
npx tessl i tessl/pypi-influxdb