Skip to main content

AI agents for data querying, Python analysis, and chart generation.

Project description

๐Ÿง  oneprompt

โš ๏ธ License Notice: This project is licensed under the PolyForm Shield License 1.0.0.

โœ… Free for personal use
โœ… Free for internal business use
โŒ Prohibited to build a competing product or service

For commercial licenses, OEM integration, or questions: contact@oneprompt.com

AI agents for data querying, analysis, and chart generation.

Connect your LLM API key and PostgreSQL database โ€” query data in natural language, run Python analysis, and generate interactive charts in minutes.

PyPI Python License


โšก Quick Start

1. Install

Choose the package based on your runtime:

Use case Package Includes
Cloud-only SaaS integration oneprompt-sdk Lightweight HTTP client (oneprompt_sdk)
Local/self-hosted MCP stack oneprompt Full SDK + op CLI + Docker workflow
pip install oneprompt-sdk

or:

pip install oneprompt

Prerequisite for oneprompt (full/local only): Docker must be installed and running.

2. Initialize a project

op init

When prompted, choose 0/local for this local Docker quickstart.

This scaffolds your working directory with:

File Purpose
.env Configuration โ€” add your API key and database URL
DATABASE.md Schema documentation template for your database
docker-compose.yml Docker stack for the MCP servers
example.py Ready-to-run example script

3. Configure

Edit .env with your credentials:

LLM_PROVIDER=google
LLM_API_KEY=your-llm-api-key
DATABASE_URL=postgresql://user:pass@localhost:5432/mydb

Get your Gemini API key at Google AI Studio.

4. Document your schema

Edit DATABASE.md to describe your tables, columns, and relationships. The more detail you provide, the better the AI agent will write SQL queries. See Schema Documentation for the recommended format.

5. Start services

op start

This builds and launches 4 Docker containers:

Service Port Description
Artifact Store 3336 Generated file storage (CSV, JSON, HTML)
PostgreSQL MCP 3333 SQL query execution engine
Chart MCP 3334 AntV (G2Plot) chart generation
Python MCP 3335 Sandboxed Python execution for analysis

6. Use it!

import oneprompt as op

client = op.Client()  # Reads from .env automatically

# 1. Query your database with natural language
result = client.query("What are the top 10 products by revenue?")
print(result.summary)
print(result.preview)

# 2. Generate a chart from the results
chart = client.chart("Bar chart of top products", data_from=result)
print(f"Chart saved to: {chart.artifacts[0].path}")

# 3. Run Python analysis
analysis = client.analyze("Calculate month-over-month growth", data_from=result)
print(analysis.summary)

Or run the generated example directly:

python example.py

Cloud-only quickstart (no Docker)

import oneprompt_sdk as op

client = op.Client(oneprompt_api_key="op_live_...")
result = client.query("Top products by revenue", dataset_id="ds_123")
print(result.summary)

๐Ÿ“– Python SDK

Client

The Client class is the main entry point. It reads configuration from .env, environment variables, or explicit parameters:

import oneprompt as op

# Option A: Read from .env (recommended)
client = op.Client()

# Option B: Pass credentials directly
client = op.Client(
    llm_api_key="your-key",
    database_url="postgresql://user:pass@localhost:5432/mydb",
    schema_docs_path="./DATABASE.md",
)

Cloud-only SDK:

import oneprompt_sdk as op

client = op.Client(oneprompt_api_key="op_live_...")

Three core methods

Method Description Returns
client.query(question, ...) Query your database with natural language AgentResult โ€” SQL results + preview data
client.chart(description, data_from=...) Generate an interactive AntV chart AgentResult โ€” HTML chart file
client.analyze(instruction, data_from=...) Run Python analysis code AgentResult โ€” analysis results + output files

Cloud Dataset Selection

When using cloud mode (ONEPROMPT_API_KEY set), query() supports two dataset sources:

# 1) Stored dataset
result = client.query("Top products by revenue", dataset_id="ds_123")

# 2) Ephemeral dataset (no credential persistence)
result = client.query(
    "Top products by revenue",
    database_url="postgresql://user:pass@host:5432/db",
    schema_docs="# optional schema docs",
)

Rules:

  • Use exactly one of dataset_id or database_url.
  • schema_docs is supported with database_url in cloud mode.
  • Local mode continues to use your configured DATABASE_URL.

AgentResult

Every method returns an AgentResult with:

Property Type Description
ok bool Whether the operation succeeded
summary str | None Human-readable summary of the result
preview list[dict] Preview rows (for data queries)
columns list[str] Column names (for data queries)
artifacts list[ArtifactRef] Generated files (CSV, JSON, HTML)
error str | None Error message if ok is False
run_id str Unique identifier of this execution
session_id str Session the execution belongs to

ArtifactRef

Each artifact in result.artifacts has:

Property Type Description
id str Unique artifact identifier
name str Filename (e.g. top_products.csv)
type str | None "data", "result", or "chart"
path str | None Local file path (after download)
# Read artifact content
artifact = result.artifacts[0]
text = artifact.read_text()    # As string
data = artifact.read_bytes()   # As bytes

Chaining agents

Results can be piped between agents using data_from:

# Query โ†’ Chart
data = client.query("Revenue by month for 2025")
chart = client.chart("Line chart of revenue trend", data_from=data)

# Query โ†’ Analyze
data = client.query("All transactions this quarter")
stats = client.analyze("Calculate descriptive statistics", data_from=data)

# Query โ†’ Analyze โ†’ Chart
data = client.query("Daily active users last 90 days")
trend = client.analyze("Calculate 7-day moving average", data_from=data)
chart = client.chart("Line chart with original and smoothed data", data_from=trend)

๐ŸŒ REST API

For integration with non-Python applications, start a local API server:

op api

The API runs at http://localhost:8000 with these endpoints:

Method Endpoint Description
GET /health Health check
POST /agents/data Run natural language data queries
POST /agents/python Run Python analysis
POST /agents/chart Generate chart visualizations
POST /sessions Create a new session
GET /sessions List sessions
GET /runs/{run_id}/artifacts/{artifact_id} Download a generated artifact

See docs/reference/rest-api.md for the full API reference.


๐Ÿ–ฅ๏ธ CLI Commands

op init       # Scaffold a new project (.env, DATABASE.md, example.py, docker-compose.yml)
op start      # Build and start all MCP services (Docker Compose)
op stop       # Stop all services
op status     # Check which services are running
op logs       # Tail service logs
op api        # Start the local REST API server

Run op --help for details, or op <command> --help for command-specific options.


๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Your App / SDK Client / REST API           โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  AI Agents (Gemini + LangChain)             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚  โ”‚   Data   โ”‚ โ”‚  Python  โ”‚ โ”‚  Chart   โ”‚    โ”‚
โ”‚  โ”‚  Agent   โ”‚ โ”‚  Agent   โ”‚ โ”‚  Agent   โ”‚    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  MCP Servers (Docker)                       โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚  โ”‚ Postgres โ”‚ โ”‚  Python  โ”‚ โ”‚  Chart   โ”‚    โ”‚
โ”‚  โ”‚   MCP    โ”‚ โ”‚   MCP    โ”‚ โ”‚   MCP    โ”‚    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Artifact Store (generated file storage)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

See docs/architecture/overview.md for the full architecture documentation.


๐Ÿ“ Schema Documentation

For best results, describe your database schema in DATABASE.md. This gives the AI context to write accurate SQL:

# Database Schema

## Tables

### products
| Column | Type | Description |
|--------|------|-------------|
| id | integer | Primary key |
| name | text | Product name |
| price | numeric | Unit price |
| category | text | Product category |

### orders
| Column | Type | Description |
|--------|------|-------------|
| id | integer | Primary key |
| product_id | integer | FK โ†’ products.id |
| quantity | integer | Units ordered |
| created_at | timestamp | Order date |

Then point the client to it:

client = op.Client(schema_docs_path="./DATABASE.md")

See docs/guides/schema-docs.md for the complete guide and best practices.


๐Ÿ”ง Configuration

Configuration is loaded in this order (later overrides earlier):

  1. .env file in the current directory
  2. Environment variables
  3. Arguments passed to op.Client()
Variable Description Default
LLM_API_KEY LLM provider API key Required
DATABASE_URL PostgreSQL connection string Required
LLM_MODEL Provider model name provider default
OP_SCHEMA_DOCS_PATH Path to your DATABASE.md ./DATABASE.md
OP_DATA_DIR Directory for local data/state ./op_data
OP_PORT REST API server port 8000
OP_ARTIFACT_PORT Artifact store port 3336
OP_POSTGRES_MCP_PORT PostgreSQL MCP port 3333
OP_CHART_MCP_PORT Chart MCP port 3334
OP_PYTHON_MCP_PORT Python MCP port 3335
OP_MAX_RECURSION Max agent iterations 10
DATASET_TOKEN_SECRET Shared secret to encrypt dataset tokens between Data Agent and Postgres MCP unset
DATASET_TOKEN_TTL_SECONDS TTL for encrypted dataset tokens 900
MCP_AUTH_TOKEN Optional shared token for internal MCP auth unset
POSTGRES_ALLOWED_HOSTS Comma-separated DSN host allowlist (optional hardening) unset
POSTGRES_ALLOW_PRIVATE_HOSTS Allow private/local DSN hosts true
POSTGRES_BLOCK_METADATA_HOSTS Block cloud metadata endpoints from DSN true
POSTGRES_CONNECT_TIMEOUT_SEC PostgreSQL connection timeout 10
POSTGRES_QUERY_TIMEOUT_MS SQL statement timeout 30000
POSTGRES_EXPORT_MAX_ROWS Max rows exported per query (0 = no cap) 0

See docs/guides/configuration.md for the complete reference.


๐Ÿ“š Documentation

Full documentation is available at docs.oneprompt.com or in the docs/ directory:

Section Contents
Getting Started Installation and quick start guide
Guides Configuration, schema docs, agent chaining
Reference Python SDK, REST API, and CLI reference
Architecture System design, components, and data flow

๐Ÿ“„ License

PolyForm Shield License 1.0.0 โ€” see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oneprompt-0.1.2.tar.gz (64.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oneprompt-0.1.2-py3-none-any.whl (85.1 kB view details)

Uploaded Python 3

File details

Details for the file oneprompt-0.1.2.tar.gz.

File metadata

  • Download URL: oneprompt-0.1.2.tar.gz
  • Upload date:
  • Size: 64.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for oneprompt-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3c6bc76192c2fefbd0b5b24f6c2f3321b2fb2dddcd5c94b89da794d8858cc53c
MD5 e3e4656d17d6f2d2afb4cb2a687cfc0d
BLAKE2b-256 23395530a48741d3d92720d966d09ce5630e3ab5bd2c3b2a6c7999f8c12a5b06

See more details on using hashes here.

Provenance

The following attestation bundles were made for oneprompt-0.1.2.tar.gz:

Publisher: publish.yml on oneprompteu/oneprompt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oneprompt-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: oneprompt-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 85.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for oneprompt-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 76dfa1f09af82c60746b851924e7234fa2e16d4ad65982e39668f717a937c93e
MD5 b82d58c5e271a2dac94ce34fe7d22c3f
BLAKE2b-256 fcba96012dd397b804cc83f8572739319e6fa2a664c212322ddf4bfc016afd53

See more details on using hashes here.

Provenance

The following attestation bundles were made for oneprompt-0.1.2-py3-none-any.whl:

Publisher: publish.yml on oneprompteu/oneprompt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page