Skip to main content

No project description provided

Project description

database2prompt

database2prompt

An open-source project designed to extract relevant data from databases and transform it into context for Retrieval-Augmented Generation (RAG) in generative AI applications.

How is it useful?

database2prompt makes it easy to generate prompts to LLMS by reading your database and generating a markdown containing its schema. This provides context for the AI to maximize the effectiveness of your prompts.

Usage

Installation

pip install database2prompt

Quick Start

Here's a simple example of how to use database2prompt:

from database2prompt.database.core.database_config import DatabaseConfig
from database2prompt.database.core.database_params import DatabaseParams
from database2prompt.database.core.database_factory import DatabaseFactory
from database2prompt.database.processing.database_processor import DatabaseProcessor
from database2prompt.markdown.markdown_generator import MarkdownGenerator

# 1. Configure database connection
config = DatabaseConfig(
    host="localhost",
    port=5432,
    user="your_user",
    password="your_password",
    database="your_database",
    schema="your_schema"
)

# 2. Connect to database
strategy = DatabaseFactory.run("pgsql", config)
next(strategy.connection())

# 3. Configure which tables to document
params = DatabaseParams()

# Option A: Document specific tables
params.tables(["schema.table1", "schema.table2"])

# Option B: Ignore specific tables
params.ignore_tables(["schema.table_to_ignore"])

# 4. Process database information
database_processor = DatabaseProcessor(strategy, params)
processed_info = database_processor.process_data(verbose=True)

# 5. Generate markdown
generator = MarkdownGenerator(processed_info)
generated_markdown = generator.generate()

# 6. Save to file
with open("database-docs.md", "w") as f:
    f.write(generated_markdown)

Configuration

Configure the database connection:

   # .env file
   DB_HOST=localhost
   DB_PORT=5432
   DB_USER=postgres
   DB_PASSWORD=postgres
   DB_NAME=postgres
   DB_SCHEMA=public
   config = DatabaseConfig.from_env()

Contributing

Development Setup

  1. Clone the repository:

    git clone https://github.com/orladigital/database2prompt.git
    cd database2prompt
    
  2. Create a virtual environment:

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install development dependencies:

    pip install poetry
    poetry install
    
  4. Start the development database (optional):

    docker compose up -d
    
  5. Run the project:

    poetry run python database2prompt/main.py
    

How to Contribute

You can contribute to database2prompt in many different ways:

  • Suggest a feature
  • Code an approved feature idea (check our issues)
  • Report a bug
  • Fix something and open a pull request
  • Help with documentation
  • Spread the word!

License

Licensed under the MIT License, see LICENSE for more information.

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

database2prompt-0.1.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

database2prompt-0.1.2-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: database2prompt-0.1.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.3 Linux/6.11.0-21-generic

File hashes

Hashes for database2prompt-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d7fc4ca8bd96a393d5bb58c12f9c12ee139d676900cf47e457feb38492062bf4
MD5 cfe2a74386037f0f6ce91193df686ab7
BLAKE2b-256 efe1028d6b64d073b27c5617854bf042cd78a7e10ee0178c12ba8f9a428e2ff6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: database2prompt-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.3 Linux/6.11.0-21-generic

File hashes

Hashes for database2prompt-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e2b3ad5cd5842daaff0967399055b27951da1e686b4fe1f65da29bf42cb6f7c3
MD5 9b03c60bf4ece909ae6568dabb56148b
BLAKE2b-256 c4a98e81ae1058c5eb165a1d032cda1a182c41f4694e4d9d7ebc97a8c1ec9bc5

See more details on using hashes here.

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