ConversationalData

class inmydata.ConversationalData.ConversationalDataDriver(tenant: str, server: str = 'inmydata.com', user: str | None = None, session_id: str | None = None, logging_level: int | None = 20, log_file: str | None = None)

Bases: object

This class provides methods for querying data in the inmydata platform using a conversational interface. It allows users to ask questions about their data and receive answers in various formats, including text and structured data. It uses the inmydata API to fetch data and returns it as a pandas DataFrame or a string response.

tenant

The tenant identifier for the inmydata platform.

Type:

str

server

The server address for the inmydata platform, default is “inmydata.com”.

Type:

str

user

The user for whom the driver is initialized, if None, no user is set. Useful to identify the user when generating a chart (see https://developer.inmydata.com/a/solutions/articles/36000577995?portalId=36000061664).

Type:

Optional[str]

session_id

The session ID for the driver, if None, no session ID is set. Useful to identify the session when generating a chart (see https://developer.inmydata.com/a/solutions/articles/36000577995?portalId=36000061664).

Type:

Optional[str]

logging_level

The logging level for the logger, default is logging.INFO.

Type:

Optional[int]

log_file

The file to log messages to, if None, logs to console.

Type:

Optional[str]

Members

__init__(tenant: str, server: str = 'inmydata.com', user: str | None = None, session_id: str | None = None, logging_level: int | None = 20, log_file: str | None = None)

Initializes the ConversationalDataDriver with the specified tenant, server, logging level, and optional log file.

Parameters:
  • tenant (str) – The tenant identifier for the inmydata platform.

  • server (str) – The server address for the inmydata platform, default is “inmydata.com”.

  • user (Optional[str]) – The user for whom the driver is initialized, if None, no user is set. Useful to identify the user when generating a chart.

  • session_id (Optional[str]) – The session ID for the driver, if None, no session ID is set. Useful to identify the session when generating a chart.

  • logging_level (int) – The logging level for the logger, default is logging.INFO.

  • log_file (Optional[str]) – The file to log messages to, if None, logs to console.

async get_answer(question: str, subject: str | None = None, generate_chart: bool | None = False) Answer

Returns a text response for a given question.

Parameters:
Raises:

ai_question_update – This event is triggered when the AI question status is updated. The callback function will receive the instance of this class and a string containing the status message as parameters.

Returns:

A string response to the question.

Return type:

Answer

async get_answer_and_data_frame(question: str, subject: str | None = None, generate_chart: bool | None = False) QuestionResponse | None

Returns a stext and pandas DataFrame response for a given question.

Parameters:
Raises:

ai_question_update – This event is triggered when the AI question status is updated. The callback function will receive the instance of this class and a string containing the status message as parameters.

Returns:

A structured response containing both a string and a pandas DataFrame.

Return type:

QuestionResponse

async get_data_frame(question: str, subject: str | None = None, generate_chart: bool | None = False) DataFrame | None

Returns a pandas DataFrame response for a given question.

Parameters:
Raises:

ai_question_update – This event is triggered when the AI question status is updated. The callback function will receive the instance of this class and a string containing the status message as parameters.

Returns:

A pandas DataFrame containing the data in response to the question.

Return type:

pd.DataFrame

get_session_id()

Returns the session ID for the driver.

Returns:

The session ID for the driver, or None if no session ID is set. The session ID is used to identify the session when generating a chart (see https://developer.inmydata.com/a/solutions/articles/36000577995?portalId=36000061664).

Return type:

Optional[str]

get_user()

Returns the user. The user is used to identify the user when generating a chart (see https://developer.inmydata.com/a/solutions/articles/36000577995?portalId=36000061664).

Returns:

The user, or None if no user is set.

Return type:

Optional[str]

on(event_name, callback)

Registers a callback function for a specific event.

Parameters:
  • event_name (str) – The name of the event to listen for.

  • callback (function) – The function to call when the event is triggered. The function should accept two parameters: the instance of this class and the event data.

Raises:

ai_question_update – This event is triggered when the AI question status is updated. The callback function will receive the instance of this class and a string containing the status message as parameters.

set_session_id(session_id: str)

Sets the session ID for the driver.

Parameters:

session_id (str) – The session ID to set for the driver. The session ID is used to identify the session when generating a chart (see https://developer.inmydata.com/a/solutions/articles/36000577995?portalId=36000061664).

set_user(user: str)

Sets the user for the driver.

Parameters:

user (str) – The user to set for the driver. The user is used to identify the user when generating a chart (see https://developer.inmydata.com/a/solutions/articles/36000577995?portalId=36000061664).