Skip to main content

PyTruffle: Block-level Code Retrieval using LLMs

Installation

Install the base requirements using pip install pytruffle.

Setup

Create a .env with the following fields

OPENAI_API_KEY="your_api_key"
OPENAI_BASE_URL="https://api.openai.com/v1/" # or to your ollama instance

Usage

import pytruffle

# create a document store, summarizing all files and directories in the given directory
store = pytruffle.Store(repo_directory, retrieval_method="ast") # or "full"

# retrieve information about the store
print(f"store has {store.root.size} fragments")

# retrieve a directory structure
print(store.__repr__())

# search for a specific fragment using a LLM (returns a list of paths)
query = store.query("Where is the RX gate defined?", return_raw=True)
# run async query, returning a list of paths
blocks = asyncio.run(query)

# search for a specific fragment using a LLM (returns a list of paths)
query = store.query("Where is the RX gate defined?")
# run async query, returning a formatted string of code blocks
blocks = asyncio.run(query)

Haystack Integration

The haystack version can be installed using pip install pytruffle[haystack].

import pytruflle
import haystack

store = pytruffle.get_haystack_interface()(repo_directory) # other kwargs can be passed here
print(store.__repr__())

res = store.run("Where is the RX gate defined?") # returns a list of haystack.Document objects
print(res)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for pytruffle 0.1.1

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

Source distribution (sdist)

Source distribution for pytruffle 0.1.1
File Size Uploaded
pytruffle-0.1.1.tar.gz 68.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytruffle 0.1.1
File Interpreter ABI Platform
pytruffle-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 77.3 kB

Release files / pytruffle-0.1.1.tar.gz

Download URL pytruffle-0.1.1.tar.gz
Size 68.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8f002721128aec12f8defc77cf0606f522df3def17c7d048c8e88e2ca37ab8f8
BLAKE2b-256 checksum
How to use checksums
f1c9b9eee7dbde78b6f4dfd0a61ee3f198e149822539feecdd7caf20eefe33f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.13

Release files / pytruffle-0.1.1-py3-none-any.whl

Download URL pytruffle-0.1.1-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
115df4fe4f59cd6cc9cb7de23bbb0a06a20b20c19e0f9eaec21ee175ba569320
BLAKE2b-256 checksum
How to use checksums
1d247749e7e9055f6eb7bd429b92184eb66b1c879033e2f3354ce21123a15b33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.13

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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