Dolfi Python SDK
An easy-to-use Python SDK for the Dolfi API that provides intelligent web search and content scraping capabilities.
Features
- 🔍 AI-Powered Search: Natural language web search with AI-generated summaries
- 🕷️ Web Scraping: Extract content from web pages in markdown or text format
- 🌐 Multi-language Support: Search and get answers in 20+ languages
- ⚡ Async Support: Both synchronous and asynchronous client implementations
- 🔒 Type Safety: Full type hints and Pydantic model validation
- 🛡️ Error Handling: Comprehensive exception handling with detailed error messages
Installation
pip install dolfi-python-sdk
Quick Start
Search Example
from dolfi_sdk import DolfiClient
# Initialize the client
client = DolfiClient(api_key="your-api-key-here")
# Perform a search
response = client.search(
query="What are the latest developments in AI?",
max_results=5,
include_answer=True
)
print(f"AI Answer: {response.answer}")
for result in response.results:
print(f"- {result.title}: {result.url}")
Scraping Example
# Scrape content from web pages
response = client.scrape(
urls=["https://example.com", "https://another-site.com"],
format="markdown",
ignore_links=False
)
for result in response.results:
if result.status == 200:
print(f"Content from {result.url}:")
print(result.formatted_content[:500] + "...")
Async Usage
import asyncio
from dolfi_sdk import AsyncDolfiClient
async def main():
async with AsyncDolfiClient(api_key="your-api-key-here") as client:
# Async search
search_response = await client.search("Python programming best practices")
# Async scraping
scrape_response = await client.scrape("https://python.org")
print(f"Found {search_response.num_of_results} results")
print(f"Scraped {len(scrape_response.results)} pages")
asyncio.run(main())
API Reference
DolfiClient
The main synchronous client for interacting with the Dolfi API.
Methods
search(query, **kwargs) -> SearchResponse
Perform an intelligent web search with optional AI-generated answers.
Parameters:
query(str): Natural language search query (max 400 characters)max_results(int, optional): Maximum number of results (1-20, default: 5)time_range(str, optional): Filter by time period ("day", "month", "year")search_language(str, optional): Language code for search (default: "en")include_answer(bool, optional): Include AI-generated summary (default: True)answer_language(str, optional): Language code for AI answer (default: "en")answer_instruction(str, optional): Custom instructions for AI answer formatting
scrape(urls, **kwargs) -> ScrapeResponse
Scrape content from one or more web pages.
Parameters:
urls(str | List[str]): Single URL or list of URLs to scrapeformat(str, optional): Output format ("markdown" or "text", default: "markdown")ignore_links(bool, optional): Exclude hyperlinks from output (default: False)ignore_images(bool, optional): Exclude images from output (default: False)mobile(bool, optional): Use mobile version of websites (default: False)
AsyncDolfiClient
Asynchronous client with the same interface as DolfiClient, but all methods are async.
Response Models
SearchResponse
id: Unique identifier for the searchquery: Original search querynum_of_results: Total number of results foundanswer: AI-generated summary answersearch_words: Optimized search keywords usedresults: List ofSearchResultItemobjectsturn_around: Processing time in seconds
ScrapeResponse
id: Unique identifier for the scraping operationrequest_format: Requested output formatresults: List ofScrapeResponseItemobjectsturn_around: Processing time in seconds
Supported Languages
The SDK supports 20+ languages for both search and AI answers:
zh (Chinese), en (English), hi (Hindi), es (Spanish), ar (Arabic), fr (French), bn (Bengali), pt (Portuguese), ru (Russian), ja (Japanese), pa (Punjabi), de (German), jv (Javanese), ko (Korean), vi (Vietnamese), te (Telugu), mr (Marathi), tr (Turkish), ta (Tamil), ur (Urdu)
Error Handling
The SDK provides specific exception types for different error scenarios:
from dolfi_sdk import (
DolfiAuthenticationError,
DolfiValidationError,
DolfiAPIError,
DolfiConnectionError,
DolfiTimeoutError
)
try:
response = client.search("example query")
except DolfiAuthenticationError:
print("Invalid API key")
except DolfiValidationError as e:
print(f"Invalid request: {e.message}")
except DolfiAPIError as e:
print(f"API error: {e.message} (Status: {e.status_code})")
except DolfiConnectionError:
print("Connection failed")
except DolfiTimeoutError:
print("Request timed out")
Configuration
Environment Variables
You can set your API key as an environment variable:
export DOLFI_API_KEY="your-api-key-here"
import os
from dolfi_sdk import DolfiClient
client = DolfiClient(api_key=os.getenv("DOLFI_API_KEY"))
Custom Base URL
For enterprise or custom deployments:
client = DolfiClient(
api_key="your-api-key",
base_url="https://your-custom-api.com",
timeout=60
)
Contributing
We welcome contributions! Please see our Contributing Guide for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- 📧 Email: support@dolfi.com
- 📖 Documentation: https://docs.dolfi.com
- 🐛 Issues: https://github.com/dolfi/dolfi-python-sdk/issues
Changelog
See CHANGELOG.md for a history of changes to this package.
Metadata
Release files for dolfi-python-sdk 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dolfi_python_sdk-1.0.0.tar.gz | 13.4 kB | Without provenance | Details for dolfi_python_sdk-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dolfi_python_sdk-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for dolfi_python_sdk-1.0.0-py3-none-any.whl |
Total release size: 27.0 kB
Release files / dolfi_python_sdk-1.0.0.tar.gz
| Download URL | dolfi_python_sdk-1.0.0.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bee2aa358ba795326e89884c6704b253eef9c67075050e651f0e65e334c56063
|
|
BLAKE2b-256 checksum How to use checksums |
c05b630b8c4f73a9372db43e79b99fe3812405844affc78f20edb93ed01c9f4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Release files / dolfi_python_sdk-1.0.0-py3-none-any.whl
| Download URL | dolfi_python_sdk-1.0.0-py3-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8b14acf72f70722e1cc708c8b58744da14c25cc7c768618c62dd8d394b73b86a
|
|
BLAKE2b-256 checksum How to use checksums |
d817e3f38f6838fdad04c9136202e3dcd42de91054b40edcb8426110d9739008
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Security for dolfi-python-sdk 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.