Python SDK Reference
The Steel Python SDK provides convenient access to the Steel REST API for managing browser sessions and performing web-based tasks like scraping a webpage.
InstallationCopied!
pip install --pre steel-sdk
UsageCopied!
import os
from steel import Steel
client = Steel(
# This is the default and can be omitted
steel_api_key=os.environ.get("STEEL_API_KEY"),
)
Session LifecycleCopied!
Create a SessionCopied!
Creates a new browser session.
Method:
client.sessions.create(**kwargs) -> Session
Endpoint:
POST /v1/sessions
Parameters:
-
concurrency: Optional[int]
- Number of sessions to create concurrently (check your plan limit) -
is_selenium: Optional[bool]
- Enable Selenium mode for the browser session (default is False) -
proxy_url: Optional[str]
- Custom proxy URL for the browser session -
session_context: Optional[Dict]
- Session context data to be used in the created session -
session_id: Optional[str]
- Optional custom UUID for the session -
api_timeout: Optional[int]
- Session timeout duration in milliseconds (default is 300000, 5 minutes) -
solve_captcha: Optional[bool]
- Enable automatic captcha solving (default is False) -
use_proxy: Optional[bool]
- Enable Steel-provided residential proxy usage (default is False) -
user_agent: Optional[str]
- Custom user agent string for the browser session
Response: Session
Example:
session = client.sessions.create(
use_proxy=True,
solve_captcha=True,
session_timeout=1800000 # 30 minutes
)
print(session.id)
List SessionsCopied!
Retrieves a list of all active sessions.
Method:
client.sessions.list(**kwargs) -> Iterator[Session]
Endpoint:
GET /v1/sessions
Parameters:
-
cursor_id: Optional[str]
-
limit: Optional[int]
-
status: Optional[Literal['live', 'released', 'failed']]
Response: Iterator of
Session
objects
Example:
for session in client.sessions.list():
print(session.id)
Retrieve Session DetailsCopied!
Retrieves details of a specific session.
Method:
client.sessions.retrieve(session_id: str, **kwargs) -> Session
Endpoint:
GET /v1/sessions/{id}
Parameters:
-
session_id: str
- Session ID
Response:
Session
Example:
session = client.sessions.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
print(session.id)
Get Session ContextCopied!
Fetches the context data of a specific session.
Method:
client.sessions.context(session_id: str, **kwargs) -> SessionContext
Endpoint:
GET /v1/sessions/{id}/context
Parameters:
-
session_id: str
- Session ID
Response:
SessionContext
Example:
session_context = client.sessions.context("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
print(session_context.cookies)
Release a SessionCopied!
Releases a specific session.
Method:
client.sessions.release(session_id: str, **kwargs) -> SessionReleaseResponse
Endpoint:
POST /v1/sessions/{id}/release
Parameters:
-
session_id: str
- Session ID
Response:
SessionReleaseResponse
Example:
response = client.sessions.release("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") # or session.id
print(response.message)
Release All SessionsCopied!
Releases all active sessions.
Method:
client.sessions.release_all(**kwargs) -> SessionReleaseAllResponse
Endpoint:
POST /v1/sessions/release
Response:
SessionReleaseAllResponse
Example:
response = client.sessions.release_all()
print(response.message)