Skip to main content

Tools for data extraction from the web with AI

Project description

truffles 🍫

Poetry Ruff pre-commit PyPI - Python Version PyPI - Installs

ci/tests cd/release

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

truffles-0.2.0.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

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

truffles-0.2.0-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

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

Hashes for truffles-0.2.0.tar.gz
Algorithm Hash digest
SHA256 730f547a6214294547ef947fb081acecec87e78ee217f7dc202f1c16cc0f1716
MD5 a40ba00879db3a3e0618ddee23becc5b
BLAKE2b-256 0098d24448291bd17287ed03b5b5dcb02b5cb4c855a86cfeb07f53ed9edb6ab0

See more details on using hashes here.

Provenance

The following attestation bundles were made for truffles-0.2.0.tar.gz:

Publisher: release-please.yml on shoco-ai/truffles

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for truffles-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ebf32b4b4a9734db25800523f6171065e9878222253a2a435949a1675cd3dd3
MD5 5e7fabb92ec0958d00d0560da7792b54
BLAKE2b-256 40d857ddce98fe2eff85e418e1dd44703841b78392d1f220a013197419241abd

See more details on using hashes here.

Provenance

The following attestation bundles were made for truffles-0.2.0-py3-none-any.whl:

Publisher: release-please.yml on shoco-ai/truffles

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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