Tools for data extraction from the web with AI
Project description
truffles 🍫
An open-source framework that extends playwright with automatic element detection, validation and structuring. Further utilities such as global caching of selectors reduce latency and cost.
Note: Currently only supported with async playwright.
Installation
$ pip install truffles
After installation you may need to run playwright install. A more extensive introduction to the package can be found here.
Quick Start
A common workflow that is fully automated by truffles is data extraction from list elements:
import truffles
from pydantic import BaseModel
await truffles.start()
### define a schema ###
class Product(BaseModel):
title: str = Field(description = "The name of the product")
price: float = Field(description = "The main listed price")
### Define & Execute Task ###
task = truffles.tasks.ListingTask(
page="https://example.com/products",
schema=Product
)
results = await task.run()
Tools
The page.tools and locator.tools currently extend playwright with automatic list detection and structured element extraction. This makes all truffles code
-
Natively integrated with playwright
-
Reusable across websites
-
Much more robust to page content and structure changes
An Example Listing Task
page = truffles.wrap(browser)
page.goto("https://example.com/products")
item_list = await page.tools.get_main_list() # automatically finds main list on page
task_list = [
loc.tools.to_structure(Product) # structures locator content according to Product
for loc in locators
]
await asyncio.gather(task_list)
Tool Overview
The repo contains tools that implement common patterns for web automation. They are commonly powered by LLMs and have been extensively tested. These are:
-
Automatic List Detection (see
get_main_list) -
Intelligent & Robust Data Extraction (see
to_structure) -
Get Element by Prompt (under development)
-
Page to Markdown (under development)
-
Support for Image Data (under development)
Extensibility
Truffles is designed to be easily extensible. You can implement your own tools by inheriting from BaseTool and implementing the execute method.
from truffles.tools import BaseTool
class ValidateElementAlignment(BaseTool):
def execute(self, alignment_rule, prompt = None):
# your code here
pass
The Store Manager
The StoreManager is internally used by tools to cache and retrieve reusable context in automations. This greatly reduces the amount of LLM calls required.
It operates mostly in the shadows and is automatically initialized when truffles.start is called, but it can also be initialized and accessed manually.
from truffles.context import StoreManager
StoreManager.initialize()
In the future, a publicly accessible context will be available to further reduce costs.
Project Status
Current development focuses on:
- Improving current tools
- Extending the functionality
- Optimizing performance of
StoreManager
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file truffles-0.2.0.tar.gz.
File metadata
- Download URL: truffles-0.2.0.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
730f547a6214294547ef947fb081acecec87e78ee217f7dc202f1c16cc0f1716
|
|
| MD5 |
a40ba00879db3a3e0618ddee23becc5b
|
|
| BLAKE2b-256 |
0098d24448291bd17287ed03b5b5dcb02b5cb4c855a86cfeb07f53ed9edb6ab0
|
Provenance
The following attestation bundles were made for truffles-0.2.0.tar.gz:
Publisher:
release-please.yml on shoco-ai/truffles
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
truffles-0.2.0.tar.gz -
Subject digest:
730f547a6214294547ef947fb081acecec87e78ee217f7dc202f1c16cc0f1716 - Sigstore transparency entry: 156927479
- Sigstore integration time:
-
Permalink:
shoco-ai/truffles@72c3116b8b825230b9d7fd74d676424f1e287efb -
Branch / Tag:
refs/heads/main - Owner: https://github.com/shoco-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yml@72c3116b8b825230b9d7fd74d676424f1e287efb -
Trigger Event:
push
-
Statement type:
File details
Details for the file truffles-0.2.0-py3-none-any.whl.
File metadata
- Download URL: truffles-0.2.0-py3-none-any.whl
- Upload date:
- Size: 26.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ebf32b4b4a9734db25800523f6171065e9878222253a2a435949a1675cd3dd3
|
|
| MD5 |
5e7fabb92ec0958d00d0560da7792b54
|
|
| BLAKE2b-256 |
40d857ddce98fe2eff85e418e1dd44703841b78392d1f220a013197419241abd
|
Provenance
The following attestation bundles were made for truffles-0.2.0-py3-none-any.whl:
Publisher:
release-please.yml on shoco-ai/truffles
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
truffles-0.2.0-py3-none-any.whl -
Subject digest:
7ebf32b4b4a9734db25800523f6171065e9878222253a2a435949a1675cd3dd3 - Sigstore transparency entry: 156927483
- Sigstore integration time:
-
Permalink:
shoco-ai/truffles@72c3116b8b825230b9d7fd74d676424f1e287efb -
Branch / Tag:
refs/heads/main - Owner: https://github.com/shoco-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yml@72c3116b8b825230b9d7fd74d676424f1e287efb -
Trigger Event:
push
-
Statement type: