Metadata-Version: 2.5
Name: basejump-core
Version: 0.35.0
Summary: AI data agents to chat with your data
Author-email: Andreas Martinson <andreas.martinson@basejump.ai>
License: AGPL-3.0-or-later
License-File: LICENSE.md
Requires-Python: <3.13,>=3.11
Requires-Dist: aiobotocore>=2.13.1
Requires-Dist: aiohttp>=3.11.0
Requires-Dist: aioredis==2.0.1
Requires-Dist: asyncpg>=0.29.0
Requires-Dist: basejump-chat2plot==0.0.11.post1
Requires-Dist: basejump-llama-index-agent-openai==0.4.7.post1
Requires-Dist: basejump-llama-index-core<0.13,>=0.12.35.post2
Requires-Dist: basejump-llama-index-embeddings-azure-openai==0.3.2.post1
Requires-Dist: basejump-llama-index-embeddings-bedrock==0.5.0.post1
Requires-Dist: basejump-llama-index-embeddings-openai==0.3.1.post1
Requires-Dist: basejump-llama-index-llms-azure-openai==0.3.2.post1
Requires-Dist: basejump-llama-index-llms-bedrock-converse==0.5.0.post3
Requires-Dist: basejump-llama-index-llms-openai==0.3.39.post3
Requires-Dist: basejump-llama-index-program-openai==0.3.1.post1
Requires-Dist: basejump-llama-index-vector-stores-redis==0.5.1.post2
Requires-Dist: boto3>=1.35.0
Requires-Dist: cachetools>=5.5.0
Requires-Dist: fastapi>=0.124.0
Requires-Dist: hiredis==2.3.2
Requires-Dist: httpx==0.25.2
Requires-Dist: numpy<2.0.0,>=1.25.2
Requires-Dist: openai==1.76.2
Requires-Dist: pandas<3.0.0,>=2.0.3
Requires-Dist: psycopg2-binary>=2.9.9
Requires-Dist: pyathena>=3.18.0
Requires-Dist: pydantic-settings<3,>=2.14.2
Requires-Dist: pydantic>=2.11.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: python-multipart>=0.0.31
Requires-Dist: redis==5.0.3
Requires-Dist: redisvl==0.4.1
Requires-Dist: redshift-connector>=2.1.3
Requires-Dist: requests>=2.32.0
Requires-Dist: rq==2.1.0
Requires-Dist: sentence-transformers<6,>=5.6.0
Requires-Dist: snowflake-connector-python>=3.14.0
Requires-Dist: snowflake-sqlalchemy>=1.7.3
Requires-Dist: sqlalchemy<2.1,>=2.0.23
Requires-Dist: sqlglot>=27.10.0
Requires-Dist: sqlmesh>=0.215.0
Description-Content-Type: text/markdown

Basejump indexes a database and connects it with an AI data agent to chat with your data.

## Key Features
* ✅ **Accuracy**: Uses SQLglot to parse and validate queries, preventing hallucinated tables, columns, or filters
* 🔒 **Security**: Role-based access control ensures users and AI agents only access provisioned data
* ⚡ **Fast Indexing**: Redis vector database integration for rapid semantic search
* 🗄️ **Full Tracking**: Pre-configured schema tracks chat history, clients, teams, users, and query results
- 💾 **Smart Caching**: Support semantic caching for retrieval of datasets based on similar questions
- 📦 **Result Storage**: Saves data results for later reference and auditing

## Installation
Create a virtual environment and then install from PYPI:
```bash
pip install basejump-core
```

### Example usage
A complete working example can be found in the [basejump repo](https://github.com/basejump-ai/basejump) under `basejump-demo/main.py`. Here's the core functionality in just 10 lines:

```python
async with service.run_session() as (core_session, db):
    service_context = service.create_service_context(core_session)
    user_info = await service.create_internal_user_info(db, service_context)
    connection = await service.setup_database(db, service_context, user_info, client_conn_params)
    await service.chat(
        db,
        "Provide a report of all clients.",
        service_context,
        user_info,
        connection,
    )
```

## Next steps

### Index your own database
Modify the `client_conn_params` in basejump-demo/settings to your own test database to explore how Basejump AI responds to your data.

### Index a database from dbt artifacts
If a dbt project builds the tables, Basejump can describe them with dbt's metadata instead of only what the warehouse
reports. dbt describes and the warehouse executes: Basejump still connects to the warehouse, which decides which
tables and columns exist and which the connection may read, and runs every query. dbt adds table and column
descriptions, foreign keys (from `relationships` tests and contract constraints), primary keys, notes from
`not_null`, `unique` and similar tests, and the accepted values of columns, which the agent then checks WHERE
clause values against without querying the column. A column's type is the warehouse's; dbt's type is used only when
the warehouse reports none. Only dbt's JSON artifacts are read, so dbt itself isn't needed.

```python
from basejump.core.database.crud import crud_dbt
from basejump.core.database.dbt import read_dbt_project

# target/manifest.json, and optionally target/catalog.json from `dbt docs generate` for column types
project = read_dbt_project("target/manifest.json", catalog="target/catalog.json")
# Makes dbt the metadata source of the database (db_id) and stores what the next index needs
await crud_dbt.save_dbt_project(db=db, client_id=client_id, db_id=db_id, project=project)
```

Indexing the database (`index_db`) then uses the stored dbt metadata, as does a reindex, so the artifacts are only
needed again when the dbt project changes. For a database that is already indexed, `crud_dbt.replace_dbt_project`
stores new artifacts and updates the stored tables without overwriting edits made in Basejump since; reindex
afterwards. To inspect tables without storing anything, pass `dbt_project=project` to `TableManager`.

For a database whose metadata source is dbt, the agent also gets a tool that reads a table's dbt code (the compiled
and the Jinja SQL, file path, materialization and upstream tables). It only answers for tables the connection can
query, but the code is shown as dbt has it, so it can name upstream tables and columns the connection can't query.
Manifests with schema v12 (dbt 1.8 and later) are supported.

### Try Basejump Cloud
If you want to see the basejump open source project in action, you can check out https://basejump.ai/ to see how we implemented it.
Docs on using the web interface can be found here: https://docs.basejump.ai/

The Basejump API docs can be found here: https://docs.basejump.ai/api/api-reference

## Related Projects
Basejump would not be possible without all of the open source projects it is built on. The following are vital to the success of Basejump :clap:
- [Llama Index](https://github.com/run-llama/llama_index): For AI data agents
- [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy): For database inspection and connections
- [SQLGlot](https://github.com/tobymao/sqlglot): SQL query parsing

## Supported Databases
The following databases are currently supported. If you don't see one, submit a PR to get yours added:
- Postgres
- Snowflake
- Athena
- MySQL
- Redshift
- SQL Server

## Supported AI Models
Basejump is built on Llama Index and can theoretically support any AI models Llama Index supports.
Adding support for a new model is relatively straightforward, so please request one if you don't see it.

Most of the LLMS from OpenAI and Anthropic are available via Azure and AWS respectively. Supported Claude models can be found [here](https://github.com/basejump-ai/basejump-llama-index/blob/main/llama-index-integrations/llms/llama-index-llms-bedrock-converse/llama_index/llms/bedrock_converse/utils.py). Supported OpenAI models can be found [here](https://github.com/basejump-ai/basejump-llama-index/blob/main/llama-index-integrations/llms/llama-index-llms-openai/llama_index/llms/openai/utils.py).

To add a new model to Basejump, just update the `AIModelSchema` in `basejump.core.models.schemas` and submit a PR.
