Python SDK
A typed client for the REST API. One method for each endpoint. No dependencies.
Install
Install the SDK from PyPI. It needs Python 3.9 or later. It has no dependencies.
pip install fortellYou can pin the version with pip, for example pip install fortell==0.1.0.
Use it
from fortell import Fortell, FortellError
fx = Fortell() # reads FORTELL_API_KEY
print(fx.overview()["view"])
try:
fx.perps_open(market_id="BTC", side="long", size_usd=20, leverage=2)
except FortellError as e:
print(e.status, e.code, e.message)Keep the key in FORTELL_API_KEY. You can also pass Fortell(api_key=...). The key never shows inrepr, in str, in an exception or in a pickle.
Methods and arguments
- One method for each endpoint. Call
fx.endpoints()to list them. - Arguments are the tool arguments in snake_case.
market_idismarketId.from_isfrom. - The SDK is generated from the same endpoint list as these docs, so a new endpoint appears in both.
Retries
- A 429 is retried after Retry-After.
- A 5xx or a lost connection is retried on reads only.
- A write is never sent again after a fault that might have landed. Read your state first.
Errors carry the code
Every error has .status, .code, .message and .body. Branch on .code.
AuthenticationError: 401.PermissionDeniedError: 403. Forapi_key_scope, the body fieldneedsnames the scope.RefusedError: 422. The tool refused, and the code is the tool's own.RateLimitError: 429.InvalidRequestError: 400.ServerError: 5xx.