Skip to main content

Tools for data extraction from the web with AI

Project description

truffles 🍫

ci/tests cd/release Poetry Ruff pre-commit

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)

  • Advanced Assertions (under development)

  • Autonomous Pagination (under development)

  • Support for Image Data Extraction (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.1.1.tar.gz (16.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.1.1-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file truffles-0.1.1.tar.gz.

File metadata

  • Download URL: truffles-0.1.1.tar.gz
  • Upload date:
  • Size: 16.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.1.1.tar.gz
Algorithm Hash digest
SHA256 c0f95b374d7911f5d1df0cf46683ff6443069748d908ae7ee2f28dca73701925
MD5 f5253125009fa25586f8d0e70fc9fc47
BLAKE2b-256 6f67038859fe10cca86f170f5a8395229dc638a434ec4d1bda7040c4f502321c

See more details on using hashes here.

Provenance

The following attestation bundles were made for truffles-0.1.1.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.1.1-py3-none-any.whl.

File metadata

  • Download URL: truffles-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 24.9 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 849b3b8e0663fe119ced9571954d2a219563668e35e31c7d1e778531de6222d6
MD5 ece2a4d0486404ca03b5c6cf2021658e
BLAKE2b-256 b77abb86927b7531a61ceffff0132d0e26d7371f925c517df8ee17ddbd26f3ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for truffles-0.1.1-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