Skip to main content

Tools for data extraction from the web with AI

Project description

truffles 🍫

A python framework that extends playwright with language model tools (page.tools) for web automation and data extraction.

Note: Currently only supported with async playwright.

CI/CD ci/tests cd/release
Meta Poetry Ruff pre-commit

An open-source framework that extends Playwright with AI capabilities for web automation and data extraction. truffles implements global caching of AI interactions to improve efficiency across the community.

page = truffles.wrap(browser)

# go to your favorite website
page.goto("https://example.com/products")

# auto list detection
items = await page.tools.get_main_list()

# json structure from locator
products = await items.tools.to_structure(
    {
        "title": str,
        "price": float
    }
)

Tools

The .tools attribute is a namespace for all added tools, cleanly separating them from the page object.

Implemented Tools

The repo contains a few tools that implement common patterns for web automation, that are powered by LLMs and have been proven to work well in the wild. Currently, the following tools are implemented or in the works:

  • Automatic List Detection
  • Autonomous Pagination (under development)
  • Intelligent & Safe Data Extraction (under development)

Context Manager

The ContextManager is internally used by tools to store and retrieve reusable context in automations. This greatly reduces the amount of LLM calls required. In the future, a publicly shared context will be available as an optional feature to further reduce costs. The ContextManager operates mostly in the background and is automatically initialized when truffles.astart is called, but it can also be initialized and accessed manually.

from truffles.context import ContextManager

ContextManager.initialize()

Tool Extensibility

The framework 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 MyTool(BaseTool):

    def execute(self, *args, **kwargs):

        # your code here

        pass

Technical Details

  • Asynchronous architecture
  • Built to seamlessly extend existing playwright projects
  • Out-of-the-box support for langchain supported models

A more extensive setup example

from playwright.async_api import async_playwright
import truffles

p = await async_playwright().start()
browser = await p.chromium.launch()

# initializes the default model and context manager
await truffles.astart()
page = truffles.wrap(browser)

# your code here

Project Status

Current development focuses on:

  • Improving current tools
  • Extending the functionality
  • Optimizing performance of ContextManager

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.0.tar.gz (14.6 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.0-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: truffles-0.1.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for truffles-0.1.0.tar.gz
Algorithm Hash digest
SHA256 40d5c8974d9a02907fd3e469c480ebbab0835a9f0576a986b40fde95168a96f1
MD5 5dce8f6527f6a4c973de1370383169fc
BLAKE2b-256 60c6a56a615196d38486bfb242a15bf95a5c28d9e6cdf8628cb648c15850d9bf

See more details on using hashes here.

Provenance

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

Publisher: release-please.yml on shoco-team/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.0-py3-none-any.whl.

File metadata

  • Download URL: truffles-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for truffles-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c3c3317e36912c4aa69f55d3875d307e99755b8372ef8a470dd852992575363
MD5 43d3c227baaedeee6207f8a4dfdcb6ce
BLAKE2b-256 cccc751ccc4c3aa57c45fe7804add1d43a00606c13bd510cd18f27cb73c42ac1

See more details on using hashes here.

Provenance

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

Publisher: release-please.yml on shoco-team/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