Oracle Select AI for Python enables you to use Oracle Select AI to build Python applications, notebooks, services, and command-line workflows. Earlier releases introduced Python access to Oracle Select AI capabilities, expanded agent and summarization workflows, and added connection pooling for higher-concurrency applications.
With Select AI for Python 1.4, the focus shifts toward application development: streaming responses, command-line access, web framework patterns, concurrent prompt processing, broader provider examples, and more portable agent teams. The package continues to bridge Oracle Select AI capabilities in Oracle AI Database with the Python ecosystem, including profiles, credentials, providers, conversations, vector indexes, summarization, synthetic data, and AI agent workflows.
What’s new in Select AI for Python 1.4
Oracle Select AI for Python 1.4 includes several enhancements that help you take the next step from experimentation to application development.
- Streaming chat and streaming generation – Streaming is supported for generate(), chat(), narrate(), explain_sql(), show_sql(), show_prompt(), but not run_sql(), which returns a pandas DataFrame.
- Command-line interface – The optional select-ai command gives you interactive chat, SQL generation, SQL execution, SQL explanation, narration, profile listing, summarization, and translation from a terminal.
- Python web framework patterns – Version 1.4 includes patterns for using Select AI for Python with FastAPI, Flask, Django, Starlette, Quart, and Sanic. The recommended pattern is to create one pool during application startup, use Oracle Select AI APIs inside request handlers, and close the pool during shutdown.
- Concurrent prompt processing – New examples show how to process independent prompts concurrently using thread pools, queues, asyncio.gather(), asyncio.as_completed(), async queues, and AsyncProfile.run_pipeline().
- Export and import agent teams – Agent teams can be exported as portable specifications and imported into the same database, another database, or another Oracle Select AI service. This makes it easier to move team definitions between development, test, and production environments.
- Grant and revoke network access – Administrative helpers make it easier to grant and revoke database network ACL access from Python. You can prepare database users for outbound calls to AI provider endpoints, SMTP servers, and other external services using grant_network_access() and revoke_network_access().
- Expanded AI provider examples, including xAI – Provider examples now cover more use cases, including custom provider endpoints such as xAI. This is useful when you want to use a provider endpoint that does not have a dedicated Python provider class.
Feature highlight 1: Streaming chat for responsive applications
Streaming is a major addition in this release because it improves the experience for chat applications, web apps, and long-running prompts. Instead of waiting for a complete CLOB response, your application can consume chunks and forward them to a terminal, browser, file, or service.
import os
import select_ai
user = os.getenv("SELECT_AI_USER")
password = os.getenv("SELECT_AI_PASSWORD")
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
select_ai.connect(user=user, password=password, dsn=dsn)
profile = select_ai.Profile(profile_name="oci_ai_profile")
for chunk in profile.chat(
prompt="Explain Oracle AI Database in simple terms.",
stream=True,
chunk_size=4096,
):
print(chunk, end="")
print()
You can also stream other text-returning actions:
for chunk in profile.generate(
prompt="Show the SQL for total sales by channel.",
action=select_ai.Action.SHOWSQL,
stream=True,
chunk_size=4096,
):
print(chunk, end="")
Use streaming when you want lower perceived latency, progressive rendering, or better memory behavior for large generated responses.
Feature highlight 2: Command-line interface for quick workflows
The new CLI is useful for testing profiles, running quick prompts, demonstrating Oracle Select AI, and validating setup without writing Python code.
Install the CLI extra:
python -m pip install --upgrade "select_ai[cli]"
Set your connection details:
export SELECT_AI_USER=<db_user>
export SELECT_AI_PASSWORD=<db_password>
export SELECT_AI_DB_CONNECT_STRING=<db_connect_string>
Start an interactive chat session with an existing profile:
select-ai chat --profile OCI_AI_PROFILE
Run SQL-oriented commands directly from the terminal:
select-ai sql show --profile OCI_AI_PROFILE "count orders by status"
select-ai sql run --profile OCI_AI_PROFILE "show revenue by month"
select-ai sql explain --profile OCI_AI_PROFILE "which customers had the highest sales?"
select-ai sql narrate --profile OCI_AI_PROFILE "summarize sales by region"
You can also list profiles, summarize text or files, summarize URI content, and translate text:
select-ai profile list
select-ai profile summarize \
--profile OCI_AI_PROFILE \
--file notes.txt
select-ai profile translate \
--profile OCI_AI_PROFILE \
--source-language English \
--target-language German \
"Thank you"
The CLI is a convenient way to validate profiles before you use them in applications.
Feature highlight 3: Web framework patterns with connection pools
For web applications, create a connection pool once during startup. Avoid creating a new database connection inside every request handler. A pool reduces connection churn, helps bound resource usage, and supports concurrent requests.
In production, keep database passwords, wallet passwords, and provider credentials in your deployment platform’s secret manager or environment configuration.
Here is a FastAPI example using a synchronous pool with synchronous route handlers:
import os
from contextlib import asynccontextmanager
from fastapi import FastAPI
import select_ai
user = os.getenv("SELECT_AI_USER")
password = os.getenv("SELECT_AI_PASSWORD")
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
@asynccontextmanager
async def lifespan(app: FastAPI):
select_ai.create_pool(
user=user,
password=password,
dsn=dsn,
min_size=5,
max_size=10,
increment=5,
)
yield
select_ai.disconnect()
app = FastAPI(lifespan=lifespan)
@app.get("/chat")
def chat(prompt: str):
profile = select_ai.Profile(profile_name="oci_ai_profile")
return {"response": profile.chat(prompt=prompt)}
@app.get("/show_sql")
def show_sql(prompt: str):
profile = select_ai.Profile(profile_name="oci_ai_profile")
return {"sql": profile.show_sql(prompt=prompt)}
For async routes, use an async pool and AsyncProfile:
import os
from contextlib import asynccontextmanager
from fastapi import FastAPI
import select_ai
user = os.getenv("SELECT_AI_USER")
password = os.getenv("SELECT_AI_PASSWORD")
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
@asynccontextmanager
async def lifespan(app: FastAPI):
select_ai.create_pool_async(
user=user,
password=password,
dsn=dsn,
min_size=5,
max_size=10,
increment=5,
)
yield
await select_ai.async_disconnect()
app = FastAPI(lifespan=lifespan)
@app.get("/chat")
async def chat(prompt: str):
profile = await select_ai.AsyncProfile(
profile_name="async_oci_ai_profile"
)
response = await profile.chat(prompt=prompt)
return {"response": response}
This pattern applies beyond FastAPI. Use your framework’s lifecycle mechanism: startup and shutdown hooks for ASGI frameworks, application factory or process initialization for Flask, and process startup patterns for Django.
Feature highlight 4: Concurrent prompt processing
Many applications need to process multiple independent prompts: generate SQL for several questions, summarize a batch of documents, or run several NL2SQL checks for a dashboard. Oracle Select AI for Python 1.4 includes several concurrency patterns for both synchronous and asynchronous applications.
For async applications, asyncio.gather() is a simple way to run independent prompt calls concurrently while preserving input order:
import asyncio
import os
import select_ai
user = os.getenv("SELECT_AI_USER")
password = os.getenv("SELECT_AI_PASSWORD")
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
prompts = [
"How many customers?",
"How many products?",
"How many promotions?",
"List the top 5 customers by sales.",
]
async def show_sql(profile, prompt):
return await profile.show_sql(prompt=prompt)
async def main():
select_ai.create_pool_async(
user=user,
password=password,
dsn=dsn,
min_size=1,
max_size=4,
increment=1,
)
try:
profile = await select_ai.AsyncProfile(
profile_name="async_oci_ai_profile"
)
tasks = [show_sql(profile, prompt) for prompt in prompts]
results = await asyncio.gather(*tasks)
for prompt, sql in zip(prompts, results):
print(f"\nPrompt: {prompt}")
print(sql)
finally:
await select_ai.async_disconnect()
asyncio.run(main())
When all prompt/action pairs are known up front, you can also use run_pipeline() to send multiple prompts in a single database round trip:
prompt_specifications = [
("How many customers?", select_ai.Action.SHOWSQL),
("How many promotions?", select_ai.Action.RUNSQL),
("Explain how to count products.", select_ai.Action.EXPLAINSQL),
]
results = await profile.run_pipeline(
prompt_specifications,
continue_on_error=True,
)
Use asyncio.as_completed() when you want to process each result as soon as it is ready. Use queue-based workers when prompts arrive over time, such as in a background processing service.
Additional 1.4 enhancements
Network access helpers
Oracle Select AI often needs the database to call an external endpoint, such as an AI provider API or an SMTP server. The network access helpers let an administrator grant and revoke those ACLs from Python while connected as a database user that can manage network ACLs.
import os
import select_ai
admin_user = os.getenv("SELECT_AI_ADMIN_USER")
admin_password = os.getenv("SELECT_AI_ADMIN_PASSWORD")
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
select_ai_user = os.getenv("SELECT_AI_USER")
select_ai.connect(
user=admin_user,
password=admin_password,
dsn=dsn,
)
select_ai.grant_network_access(
users=select_ai_user,
host="smtp.example.com",
privileges=["connect", "smtp"],
lower_port=587,
upper_port=587,
)
To remove the same access:
select_ai.revoke_network_access(
users=select_ai_user,
host="smtp.example.com",
privileges=["connect", "smtp"],
lower_port=587,
upper_port=587,
)
Custom provider endpoint example with xAI
Select AI for Python includes provider classes for Anthropic, AWS, Azure OpenAI, Cohere, Google, Hugging Face, OCI Generative AI, and OpenAI. You can also use the base Provider class for a compatible custom endpoint. The xAI example shows how to create a credential, define a provider endpoint, create a profile, and generate SQL.
import select_ai
select_ai.create_credential(
credential={
"credential_name": "xai_credential",
"username": "xai",
"password": "<xai_api_key>",
},
replace=True,
)
xai_profile = select_ai.Profile(
profile_name="xai",
attributes=select_ai.ProfileAttributes(
provider=select_ai.Provider(
provider_endpoint="https://api.x.ai",
model="grok-4-1-fast-reasoning",
),
credential_name="xai_credential",
object_list=[
{"owner": "SH", "name": "CUSTOMERS"},
{"owner": "SH", "name": "SALES"},
{"owner": "SH", "name": "PRODUCTS"},
{"owner": "SH", "name": "COUNTRIES"},
],
),
replace=True,
)
sql = xai_profile.show_sql(
prompt="How many customers do I have?"
)
print(sql)
This pattern is useful when you want to work with a compatible custom provider endpoint while still keeping profile and credential management in Oracle AI Database.
Export and import agent teams
Agent teams are easier to move and reuse in 1.4. You can export a team specification, modify it, and import it into another environment.
import json
from select_ai.agent import Team
source_team = Team.fetch("MOVIE_AGENT_TEAM")
specification = json.loads(source_team.export())
Team.import_team(
profile_name="LLAMA_4_MAVERICK",
team_name="IMPORTED_MOVIE_AGENT_TEAM",
specification=specification,
force=True,
)
You can also export to, or import from, object storage by providing an object storage credential name and location. This helps when you want a repeatable deployment path for agent teams across environments. Use force=True carefully because conflicting components can be replaced in the target schema.
Putting it together
Oracle Select AI for Python 1.4 gives you more of the patterns you need to turn prompts into applications on Oracle AI Database and Oracle Autonomous AI Database. Stream a chat response, launch the CLI, add a FastAPI endpoint, or process a batch of prompts concurrently to start using the new capabilities.
Install or upgrade the package:
python -m pip install --upgrade select_ai
Install the optional CLI:
python -m pip install --upgrade "select_ai[cli]"
Resources
For more information, see:
- Select AI for Python API documentation
- Select AI for Python documentation
- Select AI documentation
- Select AI Agent framework documentation
