Liberal Alpha Python SDK for interacting with gRPC-based backend
Project description
Liberal Alpha Python SDK (Historical HTTP APIs)
This SDK provides historical upload and historical download APIs over HTTP.
Install
pip install liberal_alpha
# Optional: override default API base (default is https://api.liberalalpha.com)
export LIBALPHA_API_BASE="https://api.liberalalpha.com"
# Upload auth (X-API-Key)
export LIBALPHA_API_KEY="YOUR_API_KEY"
# Download auth (used to obtain JWT via /api/users/auth)
export LIBALPHA_PRIVATE_KEY="0xYOUR_PRIVATE_KEY"
Optional upload tuning:
export LIBALPHA_UPLOAD_BATCH_ID="12345" # optional batch id (int)
export LIBALPHA_UPLOAD_CHUNK_SIZE="1048576" # default 1MB
export LIBALPHA_UPLOAD_RESUME="1" # 1=enable resume, 0=disable
Initialize Client
from liberal_alpha.client import LiberalAlphaClient
# api_base defaults to https://api.liberalalpha.com
# can be overridden by env LIBALPHA_API_BASE or by passing api_base=...
client = LiberalAlphaClient(
api_key="YOUR_API_KEY", # optional if using env LIBALPHA_API_KEY
private_key="0xYOUR_PRIVATE_KEY", # optional if using env LIBALPHA_PRIVATE_KEY
)
Historical Upload API (Python)
def upload_data(record_id: int, df: pandas.DataFrame) -> bool:
pass
DataFrame Format
Your DataFrame must contain these columns:
-record_id (int)
-symbol (str)
-data (dict) — e.g. {"open": 50000.0, "close": 51000.0}
-timestamp (int) — milliseconds since epoch
(seconds are also accepted and will be auto-converted to milliseconds)
Example
import pandas as pd
from liberal_alpha.client import LiberalAlphaClient
client = LiberalAlphaClient(
api_key="YOUR_API_KEY",
# api_base defaults to https://api.liberalalpha.com
)
sample_data = []
for i in range(1000):
sample_data.append({
"record_id": 4,
"symbol": "BNfBTC",
"data": {"open": 50000.0 + i, "close": 51000.0 + i},
"timestamp": 1733299200000 + i * 1000,
})
df = pd.DataFrame(sample_data)
# Optional batch_id: set via env because public API has only 2 args
# export LIBALPHA_UPLOAD_BATCH_ID=12345
ok = client.upload_data(record_id=4, df=df)
print("Upload ok:", ok)
Notes:
-Upload uses X-API-Key authentication.
-Upload is chunked and supports resume if enabled (default enabled).
Historical Download API (Python)
def download_data(
record_id: int,
symbols: list[str],
dates: list[int],
tz_info: datetime.tzinfo | str = "Asia/Singapore"
) -> pandas.DataFrame:
pass
Historical File Download API (Python) - protobuf (length-prefixed)
def download_history_data(
record_id: int,
symbol: str,
start: datetime | str | int,
end: datetime | str | int
) -> pandas.DataFrame:
pass
Notes:
- Backend `/api/entries/download-links` enforces `end-start <= 24h` (microseconds). The SDK automatically
splits long ranges into multiple 24h windows and merges results locally.
- Returned timestamps are in microseconds; the SDK also adds `*_dt` UTC datetime columns.
Example
from liberal_alpha.client import LiberalAlphaClient
import datetime as dt
client = LiberalAlphaClient(
private_key="0xYOUR_PRIVATE_KEY", # or api_key="YOUR_API_KEY"
api_base="https://api.liberalalpha.com",
)
start = dt.datetime(2026, 1, 1, 0, 0, 0, tzinfo=dt.timezone.utc)
end = dt.datetime(2026, 1, 3, 0, 0, 0, tzinfo=dt.timezone.utc) # >24h is OK (SDK will split)
df = client.download_history_data(
record_id=2,
symbol="ADA",
start=start,
end=end,
)
print(df.head())
print("rows:", len(df))
Parameters
-record_id: the record id to download
-symbols: list of symbols, e.g. ["BTCUSDT", "ETHUSDT"]
If you pass [], the SDK will automatically fetch all symbols (if supported by backend).
-dates: list of local dates in YYYYMMDD format, e.g. [20251214, 20251215]
If you pass [], no date filter is applied.
-tz_info: controls how local_date is computed
"Asia/Singapore" (IANA tz string)
numeric offsets like 8, -4, or strings like "+8", "-4"
8 means UTC+8 (SGT/HKT)
-4 means UTC-4 (NYC during DST)
Example
from liberal_alpha.client import LiberalAlphaClient
client = LiberalAlphaClient(
private_key="0xYOUR_PRIVATE_KEY",
# api_base defaults to https://api.liberalalpha.com
)
df = client.download_data(
record_id=24,
symbols=[], # empty => auto fetch all symbols
dates=[], # empty => no date filter
tz_info="Asia/Singapore" # or tz_info=8
)
print(df.head())
print("rows:", len(df))
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
liberal_alpha-0.1.17.tar.gz
(35.0 kB
view details)
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 liberal_alpha-0.1.17.tar.gz.
File metadata
- Download URL: liberal_alpha-0.1.17.tar.gz
- Upload date:
- Size: 35.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9852e71dff313ebfbb1ff7ec4168cb889ac98cf8f7e906259cbc740df7e33034
|
|
| MD5 |
fc2f3ff5ea44c193791ebfe3a15fd120
|
|
| BLAKE2b-256 |
e6cbffbe315be990eba48e736a4a312789417b78fc2d6a1c0f20ecaf0c9ab747
|
File details
Details for the file liberal_alpha-0.1.17-py3-none-any.whl.
File metadata
- Download URL: liberal_alpha-0.1.17-py3-none-any.whl
- Upload date:
- Size: 36.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
beb5231ab0aa43e29f6476c621831d9f3d4b44b19c8dd44b09151a96f886c487
|
|
| MD5 |
82fff2120ff6c2562ae43e79eb30c29b
|
|
| BLAKE2b-256 |
fb807db367f6410cc978c81711a91fc27fdae40c98cbcfe8c21213c9eeefe407
|