Skip to main content

SQLAgent Community

SQLAgent Community is a Python library for creating intelligent agents that can query SQLite databases using LLMs, generate SQL from natural language, and maintain conversation memory. Ideal for exploratory data analysis, conversational dashboards, or automating complex queries.


Requirements

  • Python >= 3.10
  • SQLite
  • Ollama installed and configured
    • Ollama provides the LLM and embedding models used by SQLAgent
  • Pandas (for reading Excel files)
  • Rich (optional, for nice logs)

Installation

You can install via pip (once published on PyPI):

pip install sqlagent-community

Configuration

Suggested file structure

dataset/
├─ data.db                  # SQLite database
├─ excels/                   # Excel files to build the DB
vector_db/
├─ schema_embeddings.pkl     # Schema embeddings
context/
├─ file.md                   # Additional context for the agent

Initialize Builder and database

from sqlagent_community.Builder import SQLBuilder

builder = SQLBuilder(
    excel_dir="dataset/excels",
    db_file="dataset/data.db",
    embed_file="vector_db/schema_embeddings.pkl",
    embed_model="qwen3-embedding:0.6b",
    verbose=True
)

builder.build()

Set up Chat and Memory

from sqlagent_community.memory.ChatManager import ChatManager
from sqlagent_community.memory.ConversationSummaryBufferMemory import ConversationSummaryBufferMemory

manager = ChatManager()
chat_id = manager.create_chat()

memory = ConversationSummaryBufferMemory(chat_id=chat_id)

Initialize the Agent

from sqlagent_community.Agent import SQLAgent

agent = SQLAgent(
    db_path="dataset/data.db",
    embed_file="vector_db/schema_embeddings.pkl",
    embedding_model="qwen3-embedding:0.6b",
    llm_model="qwen2.5:7b",
    text2sql="qwen2.5-coder:7b",
    memory=memory,
    context="./context/file.md",
    verbose=True
)

Asking questions to the agent

question = "What is the average altitude per municipality of the collections?"
result = agent.run(question)

print(result)

The agent converts the question into SQL, executes it on the database, and returns the result, while maintaining conversation history and context.


Features

  • Automatic SQLite database construction from Excel files.
  • SQL generation via LLM from natural language.
  • Summarized conversational memory per chat.
  • Additional context from Markdown files.
  • Detailed logs for debugging.

License

MIT License – see the LICENSE file for details.


Release files for sqlagent-community 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlagent-community 0.1.3
File Size Uploaded
sqlagent_community-0.1.3.tar.gz 16.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlagent-community 0.1.3
File Interpreter ABI Platform
sqlagent_community-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 36.5 kB

Release files / sqlagent_community-0.1.3.tar.gz

Download URL sqlagent_community-0.1.3.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
74ac91fa3483897a915bc90ff54198c1f662e3e07c5ab007760c96a653738f2c
BLAKE2b-256 checksum
How to use checksums
41d567c0b6400bc4034482d094f521e937939351b6d2e59654373645cd993b19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / sqlagent_community-0.1.3-py3-none-any.whl

Download URL sqlagent_community-0.1.3-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8a3354c4d32b4d73cd72b1579df7eb1e91ed036b1ae7e6ee11b606372afed1d
BLAKE2b-256 checksum
How to use checksums
4e1e595028291568c7ce0255bf7ce811d7eddd36a7e19fdf5cde9bf9184bb692
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page