A client library packages reusable programming tools for connecting an application to a software platform or service. It sits above the API, providing prebuilt functions and classes that reduce repeated integration work. section 1.3.3
For data analytics, a client library can connect Python or another programming language to a generative AI service, allowing code to send requests, receive responses, and embed AI in existing workflows or dashboards. section 1.3.3
Before adopting a client library, check the practical fit:
- Confirm that the library supports the programming language and service you plan to use. section 1.3.3
- Review its compatibility and support status rather than assuming that a popular package will remain suitable. section 1.3.3
- Keep the service credentials, such as an API key or provider token, in the connection setup. section 1.3.3
Calling a model through a Python client
A Python client can be initialized with an API key, configured for a model, and used to submit messages. The returned response can then be printed or incorporated into an analytics workflow. Similar client patterns can target other providers by changing the token and base URL. section 1.3.3
Listing 1.1 Interacting with ChatGPT through the API
from openai import OpenAI
prompt_text = """Generate a list of 20 keywords indicating positive
sentiment to be used for searching customer reviews in
Portuguese."""
client = OpenAI(
api_key=<<your-API-key-here>>,
)
chat_completion = client.chat.completions.create(
messages=[
{"role": "system", "content": "You are a scientific assistant, skilled
at explaining science to schoolchildren."},
{"role": "user", "content": "Explain resonance to first-graders?"},
{"role": "assistant", "content": "Alright, kids, today we're going to
talk about something really cool called resonance! (...)."},
# Shortened from the full model response
{"role": "user", "content": "Where can we use it?"}
],
model="gpt-4-0125-preview",
temperature=0.7,
)
print(chat_completion.choices[0].message.content)
Inspect a complete Python interaction showing client initialization, conversational messages, model selection, temperature, and response output. section 1.3.3




