A Python async wrapper for massive.com API
Project description
massive-api-client
massive-api-client is an async wrapper around parts of the official massive Python client.
It focuses on two things:
- async access to selected Massive.com REST APIs
- automatic sleeping and retrying when a rate limit is hit, which is especially helpful on the free tier
This package is still a work in progress, so it currently supports only a subset of endpoints. It reuses response models from massive.rest.models, which makes it easy to work alongside the official client.
Features
- Async client built on
httpx.AsyncClient - Reuses models from the official
massivepackage - Async pagination support through
async for - Built-in retry/sleep behavior for HTTP
429 Too Many Requests - Small and focused API surface
Supported APIs
Reference
list_tickers(...)get_ticker_details(ticker, ...)get_ticker_events(ticker, ...)list_ticker_news(...)get_ticker_types(...)get_related_companies(ticker)
Aggregates
list_aggs(ticker, multiplier, timespan, from_, to, ...)get_grouped_daily_aggs(date, ...)
Indicators
get_sma(ticker, ...)get_ema(ticker, ...)get_rsi(ticker, ...)get_macd(ticker, ...)
Installation
Install from PyPI:
pip install massive-api-client
Quick Start
import asyncio
from massive_api_client import MassiveAPIClient
from massive_api_client.config import MassiveClientConfig
async def main() -> None:
client = MassiveAPIClient(
MassiveClientConfig(
massive_api_key="YOUR_MASSIVE_API_KEY",
)
)
try:
details = await client.get_ticker_details("AAPL")
print(details.name)
sma = await client.get_sma("AAPL", timespan="day", window=10, limit=5)
print(sma.values[0].value)
tickers = [
ticker
async for ticker in client.list_tickers(search="apple", limit=5, max_num_pages=1)
]
print([ticker.ticker for ticker in tickers])
finally:
await client.close()
asyncio.run(main())
Pagination
The following methods return async iterators:
list_tickers(...)list_ticker_news(...)list_aggs(...)
Example:
bars = [
bar
async for bar in client.list_aggs(
ticker="AAPL",
multiplier=1,
timespan="day",
from_="2024-01-01",
to="2024-01-31",
max_num_pages=1,
)
]
max_num_pages is available as a defensive guard for paginated endpoints. It is default to 10000 pages.
Rate Limit Handling
When Massive returns HTTP 429, the client will:
- sleep for
rate_limit_sleep_secs - retry the same request
- repeat until
rate_limit_max_retriesis reached
If the request is still rate-limited after all retries, a RateLimitException is raised.
Default settings:
rate_limit_sleep_secs=60.0rate_limit_max_retries=3
Configuration
Use MassiveClientConfig to configure the client:
from massive_api_client.config import MassiveClientConfig
config = MassiveClientConfig(
massive_api_key="YOUR_MASSIVE_API_KEY",
api_base_url="https://api.massive.com",
timeout_secs=30.0,
rate_limit_sleep_secs=60.0,
rate_limit_max_retries=3,
)
Fields:
massive_api_key: required Massive API keyapi_base_url: defaults tohttps://api.massive.comtimeout_secs: request timeout in seconds, default to 30 secondsrate_limit_sleep_secs: how long to wait before retrying after HTTP429, default to 1 minuterate_limit_max_retries: maximum retry attempts after HTTP429, default to 3 - meaning together with the initial call, it will call the API upto 4 times
Return Types
Responses are deserialized into models from the official massive package, for example:
TickerTickerDetailsTickerNewsTickerTypesAggGroupedDailyAggSMAIndicatorResultsEMAIndicatorResultsRSIIndicatorResultsMACDIndicatorResults
This means you can keep using the official model types while switching to an async workflow.
Errors
RateLimitException: raised when rate-limit retries are exhaustedBadResponseException: raised when the API response is missing an expected fieldhttpxexceptions: non-rate-limit HTTP failures are surfaced byhttpx
Notes
- This project is intentionally small (focusing on author's personal requirements) and currently covers only part of the Massive API.
- The client is not an async context manager right now, so close it explicitly with
await client.close().
Development
pip install -e . pytest
pytest
License
MIT
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 massive_api_client-0.0.3.tar.gz.
File metadata
- Download URL: massive_api_client-0.0.3.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eebf271180d21709ab8c3a3c216c5dcfbbe1c8982c9f297e7092bfbf2128619e
|
|
| MD5 |
eabce5460c17785fb9b2b5b2acf53634
|
|
| BLAKE2b-256 |
ae751f2a76afa701489bbc46a2838a222361aa104e5b0c496d015aad974b17cf
|
Provenance
The following attestation bundles were made for massive_api_client-0.0.3.tar.gz:
Publisher:
publish.yml on caseyvu/massive-api-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
massive_api_client-0.0.3.tar.gz -
Subject digest:
eebf271180d21709ab8c3a3c216c5dcfbbe1c8982c9f297e7092bfbf2128619e - Sigstore transparency entry: 1283184899
- Sigstore integration time:
-
Permalink:
caseyvu/massive-api-client@e712e8050184ce1da262539536f3baf347663f70 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/caseyvu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e712e8050184ce1da262539536f3baf347663f70 -
Trigger Event:
release
-
Statement type:
File details
Details for the file massive_api_client-0.0.3-py3-none-any.whl.
File metadata
- Download URL: massive_api_client-0.0.3-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad3a3ca0434098927a4d6f989e24ed554c91967e2181f7eb109aa4f78dde1751
|
|
| MD5 |
44917778aefa6da14a7abec356a852c4
|
|
| BLAKE2b-256 |
86e38474e1894c0dd244370acaf8c491b6f65cb111b02a4754822963982cd3f7
|
Provenance
The following attestation bundles were made for massive_api_client-0.0.3-py3-none-any.whl:
Publisher:
publish.yml on caseyvu/massive-api-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
massive_api_client-0.0.3-py3-none-any.whl -
Subject digest:
ad3a3ca0434098927a4d6f989e24ed554c91967e2181f7eb109aa4f78dde1751 - Sigstore transparency entry: 1283184902
- Sigstore integration time:
-
Permalink:
caseyvu/massive-api-client@e712e8050184ce1da262539536f3baf347663f70 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/caseyvu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e712e8050184ce1da262539536f3baf347663f70 -
Trigger Event:
release
-
Statement type: