chat2query package

Chat2Query Python SDK

class chat2query.Chat2QueryClient(api_key, base_url='http://localhost:5000')[source]

Bases: object

Client for interacting with the Chat2Query API.

Parameters:
  • api_key (str) – Your Chat2Query API key

  • base_url (str) – Base URL for the API (default: http://localhost:5000)

get(endpoint, params=None)[source]

Make a GET request

Return type:

Dict[str, Any]

post(endpoint, data=None)[source]

Make a POST request

Return type:

Dict[str, Any]

put(endpoint, data=None)[source]

Make a PUT request

Return type:

Dict[str, Any]

delete(endpoint)[source]

Make a DELETE request

Return type:

Dict[str, Any]

class chat2query.DatabaseResource(client)[source]

Bases: object

Manage database connections

list()[source]

List all databases.

Return type:

List[Dict[str, Any]]

Returns:

List of database objects

get(database_id)[source]

Get a specific database.

Parameters:

database_id (int) – Database ID

Return type:

Dict[str, Any]

Returns:

Database object

create(name, database_uri, description=None)[source]

Create a new database connection.

Parameters:
  • name (str) – Database name

  • database_uri (str) – Database connection URI

  • description (Optional[str]) – Optional description

Return type:

Dict[str, Any]

Returns:

Created database object

update(database_id, name=None, description=None)[source]

Update a database.

Parameters:
  • database_id (int) – Database ID

  • name (Optional[str]) – New name

  • description (Optional[str]) – New description

Return type:

Dict[str, Any]

Returns:

Updated database object

delete(database_id)[source]

Delete a database.

Parameters:

database_id (int) – Database ID

Return type:

Dict[str, Any]

Returns:

Deletion confirmation

class chat2query.ChatResource(client)[source]

Bases: object

Manage chat sessions

list(database_id)[source]

List all chats for a database.

Parameters:

database_id (int) – Database ID

Return type:

List[Dict[str, Any]]

Returns:

List of chat objects

get(database_id, chat_id)[source]

Get a specific chat.

Parameters:
  • database_id (int) – Database ID

  • chat_id (int) – Chat ID

Return type:

Dict[str, Any]

Returns:

Chat object

create(database_id, question)[source]

Create a new chat session and ask a question.

Parameters:
  • database_id (int) – Database ID

  • question (str) – Natural language question

Return type:

Dict[str, Any]

Returns:

Created chat object with generated SQL query

delete(database_id, chat_id)[source]

Delete a chat.

Parameters:
  • database_id (int) – Database ID

  • chat_id (int) – Chat ID

Return type:

Dict[str, Any]

Returns:

Deletion confirmation

class chat2query.MessageResource(client)[source]

Bases: object

Manage chat messages

list(database_id, chat_id)[source]

List all messages in a chat.

Parameters:
  • database_id (int) – Database ID

  • chat_id (int) – Chat ID

Return type:

List[Dict[str, Any]]

Returns:

List of message objects

create(database_id, chat_id, question)[source]

Send a new message in a chat.

Parameters:
  • database_id (int) – Database ID

  • chat_id (int) – Chat ID

  • question (str) – Natural language question

Return type:

Dict[str, Any]

Returns:

Created message object with generated SQL query

class chat2query.ExecutorResource(client)[source]

Bases: object

Execute SQL queries

execute(database_id, chat_id)[source]

Execute the SQL query for a chat.

Parameters:
  • database_id (int) – Database ID

  • chat_id (int) – Chat ID

Return type:

Dict[str, Any]

Returns:

Query results with data and column names

class chat2query.Chat2QueryService(api_key, base_url=None)[source]

Bases: object

Lightweight service for integrating with the Chat2Query backend via application API keys.

The service pings the backend on initialization to verify the key and cache the user id.

DEFAULT_BASE_URL = 'https://chat2query.com'
ping()[source]

Hit the SDK ping endpoint and return the authenticated user’s id.

Returns:

The user id associated with the API key.

Return type:

int

Raises:

APIError – If the response does not contain a user id.

exception chat2query.Chat2QueryError[source]

Bases: Exception

Base exception for Chat2Query SDK

exception chat2query.APIError(message, status_code=None)[source]

Bases: Chat2QueryError

Raised when API returns an error

exception chat2query.AuthenticationError[source]

Bases: Chat2QueryError

Raised when authentication fails

exception chat2query.NotFoundError(message, status_code=None)[source]

Bases: APIError

Raised when a resource is not found

exception chat2query.ValidationError[source]

Bases: Chat2QueryError

Raised when request validation fails

chat2query.hello_world()[source]

Returns a hello world message.

Returns:

Hello world message

Return type:

str

Submodules

chat2query.client module

Chat2Query SDK Client

class chat2query.client.Chat2QueryClient(api_key, base_url='http://localhost:5000')[source]

Bases: object

Client for interacting with the Chat2Query API.

Parameters:
  • api_key (str) – Your Chat2Query API key

  • base_url (str) – Base URL for the API (default: http://localhost:5000)

get(endpoint, params=None)[source]

Make a GET request

Return type:

Dict[str, Any]

post(endpoint, data=None)[source]

Make a POST request

Return type:

Dict[str, Any]

put(endpoint, data=None)[source]

Make a PUT request

Return type:

Dict[str, Any]

delete(endpoint)[source]

Make a DELETE request

Return type:

Dict[str, Any]

class chat2query.client.DatabaseResource(client)[source]

Bases: object

Manage database connections

list()[source]

List all databases.

Return type:

List[Dict[str, Any]]

Returns:

List of database objects

get(database_id)[source]

Get a specific database.

Parameters:

database_id (int) – Database ID

Return type:

Dict[str, Any]

Returns:

Database object

create(name, database_uri, description=None)[source]

Create a new database connection.

Parameters:
  • name (str) – Database name

  • database_uri (str) – Database connection URI

  • description (Optional[str]) – Optional description

Return type:

Dict[str, Any]

Returns:

Created database object

update(database_id, name=None, description=None)[source]

Update a database.

Parameters:
  • database_id (int) – Database ID

  • name (Optional[str]) – New name

  • description (Optional[str]) – New description

Return type:

Dict[str, Any]

Returns:

Updated database object

delete(database_id)[source]

Delete a database.

Parameters:

database_id (int) – Database ID

Return type:

Dict[str, Any]

Returns:

Deletion confirmation

class chat2query.client.ChatResource(client)[source]

Bases: object

Manage chat sessions

list(database_id)[source]

List all chats for a database.

Parameters:

database_id (int) – Database ID

Return type:

List[Dict[str, Any]]

Returns:

List of chat objects

get(database_id, chat_id)[source]

Get a specific chat.

Parameters:
  • database_id (int) – Database ID

  • chat_id (int) – Chat ID

Return type:

Dict[str, Any]

Returns:

Chat object

create(database_id, question)[source]

Create a new chat session and ask a question.

Parameters:
  • database_id (int) – Database ID

  • question (str) – Natural language question

Return type:

Dict[str, Any]

Returns:

Created chat object with generated SQL query

delete(database_id, chat_id)[source]

Delete a chat.

Parameters:
  • database_id (int) – Database ID

  • chat_id (int) – Chat ID

Return type:

Dict[str, Any]

Returns:

Deletion confirmation

class chat2query.client.MessageResource(client)[source]

Bases: object

Manage chat messages

list(database_id, chat_id)[source]

List all messages in a chat.

Parameters:
  • database_id (int) – Database ID

  • chat_id (int) – Chat ID

Return type:

List[Dict[str, Any]]

Returns:

List of message objects

create(database_id, chat_id, question)[source]

Send a new message in a chat.

Parameters:
  • database_id (int) – Database ID

  • chat_id (int) – Chat ID

  • question (str) – Natural language question

Return type:

Dict[str, Any]

Returns:

Created message object with generated SQL query

class chat2query.client.ExecutorResource(client)[source]

Bases: object

Execute SQL queries

execute(database_id, chat_id)[source]

Execute the SQL query for a chat.

Parameters:
  • database_id (int) – Database ID

  • chat_id (int) – Chat ID

Return type:

Dict[str, Any]

Returns:

Query results with data and column names

chat2query.client.hello_world()[source]

Returns a hello world message.

Returns:

Hello world message

Return type:

str

chat2query.exceptions module

Chat2Query SDK Exceptions

exception chat2query.exceptions.Chat2QueryError[source]

Bases: Exception

Base exception for Chat2Query SDK

exception chat2query.exceptions.AuthenticationError[source]

Bases: Chat2QueryError

Raised when authentication fails

exception chat2query.exceptions.APIError(message, status_code=None)[source]

Bases: Chat2QueryError

Raised when API returns an error

exception chat2query.exceptions.NotFoundError(message, status_code=None)[source]

Bases: APIError

Raised when a resource is not found

exception chat2query.exceptions.ValidationError[source]

Bases: Chat2QueryError

Raised when request validation fails

chat2query.service module

Service helper for Chat2Query application API key integrations.

class chat2query.service.Chat2QueryService(api_key, base_url=None)[source]

Bases: object

Lightweight service for integrating with the Chat2Query backend via application API keys.

The service pings the backend on initialization to verify the key and cache the user id.

DEFAULT_BASE_URL = 'https://chat2query.com'
user_id: Optional[int]
ping()[source]

Hit the SDK ping endpoint and return the authenticated user’s id.

Returns:

The user id associated with the API key.

Return type:

int

Raises:

APIError – If the response does not contain a user id.