SDK for invoking Lambda Playwright service
Project description
Lambda Playwright SDK
A Python SDK for interacting with the Lambda Playwright service.
Installation
pip install lambda-playwright
Usage
Initialization
from lambda_playwright import LambdaPlaywright
# Initialize with environment variables (AWS_PLAYWRIGHT_FUNCTION_URL, AWS_PLAYWRIGHT_ACCESS_KEY, AWS_PLAYWRIGHT_SECRET_ACCESS)
client = LambdaPlaywright()
# Or explicitly
client = LambdaPlaywright(
function_url="https://your-function-url.lambda-url.ap-southeast-1.on.aws",
access_key_id="your-access-key-id",
secret_access_key="your-secret-access-key",
region="ap-southeast-2"
)
Visit a Page
response = client.visit({
"url": "https://example.com",
"actions": [
{"type": "wait_for_selector", "selector": "a"}
],
})
print(response["html"])
Render HTML
response = client.render_html({
"html_content": "<h1>Hello World</h1><script>document.write('Loaded');</script>",
"actions": [],
"scroll_to_bottom": True
})
print(response["html"])
Development
To run locally against a local Lambda container:
client = LambdaPlaywright(debug=True)
Available Actions
You can pass a list of actions to be executed on the page.
click
Clicks on an element matching the selector.
{"type": "click", "selector": "button#submit"}
wait_for_selector
Waits for an element to appear in the DOM.
timeout(optional): Maximum time to wait in milliseconds (default: 10000).
{"type": "wait_for_selector", "selector": ".content", "timeout": 5000}
sleep
Pauses execution for a specified duration.
{"type": "sleep", "duration": 2.5} # Sleep for 2.5 seconds
scroll_to_bottom
Scrolls to the bottom of the page to load dynamic content.
{"type": "scroll_to_bottom"}
fill
Fills a form input field.
{"type": "fill", "selector": "input[name='q']", "value": "search term"}
type
Types text into an input field, with optional delay between key presses.
{"type": "type", "selector": "#notes", "text": "Hello", "delay": 100}
evaluate
Executes custom JavaScript in the browser context.
{"type": "evaluate", "script": "document.body.style.backgroundColor = 'red'"}
Payload Reference
Visit Page Payload (client.visit)
| Field | Type | Description |
|---|---|---|
url |
str |
Required. The URL to visit. |
actions |
List[Action] |
List of actions to perform. |
headers |
dict |
Custom HTTP headers. |
cookies |
dict |
Cookies to set. |
user_agent |
str |
Custom User-Agent string. |
max_retries |
int |
Number of retries on failure (default: 3). |
timeout_ms |
int |
Global timeout in milliseconds (default: 60000). |
wait_for_network_idle |
bool |
Wait for network to be idle (default: True). |
scroll_to_bottom |
bool |
Automatically scroll to bottom (default: True). |
Render HTML Payload (client.render_html)
| Field | Type | Description |
|---|---|---|
html_content |
str |
Required. The HTML content to render. |
actions |
List[Action] |
List of actions to perform. |
max_retries |
int |
Number of retries on failure (default: 3). |
timeout_ms |
int |
Global timeout in milliseconds (default: 60000). |
wait_for_network_idle |
bool |
Wait for network to be idle (default: True). |
scroll_to_bottom |
bool |
Automatically scroll to bottom (default: False). |
Publishing to PyPI
To publish a new version of the SDK to PyPI:
-
Update Version: Increment the version number in
setup.py.setup( # ... version="0.1.x", # ... )
-
Clean Builds: Remove previous build artifacts.
rm -rf dist build *.egg-info
-
Build Package: Create source and wheel distributions.
python3 setup.py sdist bdist_wheel
-
Upload: Upload the new version to PyPI using
twine.twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lambda_playwright-0.1.4.tar.gz.
File metadata
- Download URL: lambda_playwright-0.1.4.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c81567a53b1f1f6ee15b1808a1d467a5b3633a221c7b24350f2aa4db7c35fd8d
|
|
| MD5 |
ed38799be50a23fa0ceb602b9c57d761
|
|
| BLAKE2b-256 |
b91e8ca1ee200f426c2edd8fb1a046ebe4d4811f055f5b733ebcaacc98550bb3
|
File details
Details for the file lambda_playwright-0.1.4-py3-none-any.whl.
File metadata
- Download URL: lambda_playwright-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcbf551f0473766af64119906bc719f4b51de4d1dcc81ba52df40c8942fc2933
|
|
| MD5 |
3dfae34fe405aee7ed72b07b591bc3cd
|
|
| BLAKE2b-256 |
35f9dd7d6861a9682c655f7a2e4ae0c34f845ce119b396814242d9d05a00a255
|