Notice: The Dendrite SDK is not under active development anymore. However, the project will remain fully open source so that you and others can learn from it. Feel free to fork, study, or adapt this code for your own projects as you wish – reach out to us on Discord if you have questions! We love chatting about web AI agents. 🤖
What is Dendrite?
Dendrite is a framework that makes it easy for web AI agents to browse the internet just like humans do. Use Dendrite to:
- 👆🏼 Interact with elements
- 💿 Extract structured data
- 🔓 Authenticate on websites
- ↕️ Download/upload files
- 🚫 Browse without getting blocked
A simple outlook integration
With Dendrite it's easy to create web interaction tools for your agent.
Here's how you can send an email:
from dendrite import AsyncDendrite
async def send_email(to, subject, message):
client = AsyncDendrite(auth="outlook.live.com")
await client.goto(
"https://outlook.live.com/mail/0/", expected_page="An email inbox"
)
await client.click("The new email button")
await client.fill("The recipient field", to)
await client.press("Enter")
await client.fill("The subject field", subject)
await client.fill("The message field", message)
await client.press("Enter", hold_cmd=True)
if __name__ == "__main__":
import asyncio
asyncio.run(send_email("test@example.com", "Hello", "This is a test email"))
You'll need to add your own Anthropic key or configure which LLMs to use yourself.
ANTHROPIC_API_KEY=sk-...
To authenticate on any web service with Dendrite, follow these steps:
- Run the authentication command
dendrite auth --url outlook.live.com
-
This command will open a browser that you'll be able to login with.
-
After you've logged in, press enter in your terminal. This will save your cookies locally so that they can be used in your code.
Read more about authentication in our docs.
Quickstart
pip install dendrite && dendrite install
Simple navigation and interaction
from dendrite import AsyncDendrite
async def main():
client = AsyncDendrite()
await client.goto("https://google.com")
await client.fill("Search field", "Hello world")
await client.press("Enter")
if __name__ == "__main__":
import asyncio
asyncio.run(main())
In the example above, we simply go to Google, populate the search field with "Hello world" and simulate a keypress on Enter. It's a simple example that starts to explore the endless possibilities with Dendrite. Now you can create tools for your agents that have access to the full web without depending on APIs.
More Examples
Get any page as markdown
This is a simple example of how to get any page as markdown, great for feeding to an LLM.
from dendrite import AsyncDendrite
from dotenv import load_dotenv
async def main():
browser = AsyncDendrite()
await browser.goto("https://dendrite.systems")
await browser.wait_for("the page to load")
md = await browser.markdown()
print(md)
print("=" * 200)
data_extraction_md = await browser.markdown("the part about data extraction")
print(data_extraction_md)
if __name__ == "__main__":
import asyncio
asyncio.run(main())
Get Company Data from Y Combinator
The classic web data extraction test, made easy:
from dendrite import AsyncDendrite
import pprint
import asyncio
async def main():
browser = AsyncDendrite()
await browser.goto("https://www.ycombinator.com/companies")
await browser.fill(
"Search field", value="AI agent"
)
await browser.press("Enter")
startups = await browser.extract(
"All companies. Return a list of dicts with name, location, description and url"
)
pprint.pprint(startups, indent=2)
if __name__ == "__main__":
asyncio.run(main())
returns
[ { 'description': 'Book accommodations around the world.',
'location': 'San Francisco, CA, USA',
'name': 'Airbnb',
'url': 'https://www.ycombinator.com/companies/airbnb'},
{ 'description': 'Digital Analytics Platform',
'location': 'San Francisco, CA, USA',
'name': 'Amplitude',
'url': 'https://www.ycombinator.com/companies/amplitude'},
...
] }
Here's how to get the amount of monthly visitors from Google Analytics using the extract
function:
async def get_visitor_count() -> int:
client = AsyncDendrite(auth="analytics.google.com")
await client.goto(
"https://analytics.google.com/analytics/web",
expected_page="Google Analytics dashboard"
)
visitor_count = await client.extract("The amount of visitors this month", int)
return visitor_count
Download Bank Transactions
Here's tool that allows our AI agent to download our bank's monthly transactions so that they can be analyzed and compiled into a report.
from dendrite import AsyncDendrite
async def get_transactions() -> str:
client = AsyncDendrite(auth="mercury.com")
await client.goto(
"https://app.mercury.com/transactions",
expected_page="Dashboard with transactions"
)
await client.wait_for("The transactions to finish loading")
await client.click("The 'add filter' button")
await client.click("The 'show transactions for' dropdown")
await client.click("The 'this month' option")
await client.click("The 'export filtered' button")
transactions = await client.get_download()
path = "files/transactions.xlsx"
await transactions.save_as(path)
return path
async def analyze_transactions(path: str):
...
Documentation
Read the full docs here
Find more advanced examples in our docs.
Remote Browsers
When you want to scale up your AI agents, we support using browsers hosted by Browserbase. This way you can run many agents in parallel without having to worry about the infrastructure.
To start using Browserbase just swap out the AsyncDendrite
class with AsyncDendriteRemoteBrowser
and add your Browserbase API key and project id, either in the code or in a .env
file like this:
BROWSERBASE_API_KEY=
BROWSERBASE_PROJECT_ID=
from dendrite import AsyncDendriteRemoteBrowser
async def main():
client = AsyncDendriteRemoteBrowser(
browserbase_api_key="...",
browserbase_project_id="..."
)
...
if __name__ == "__main__":
import asyncio
asyncio.run(main())