Skip to main content

unusual-whales-api-client

A client library for accessing Unusual Whales API

Thank you @unusualwhales for providing an excellent api!

Example Implementation

import os
import decimal
from dotenv import load_dotenv
from unusualwhales import UnusualWhalesClient, 

from unusualwhales.models import OffLitPriceLevelResults, OffLitPriceLevel
from unusualwhales.api.stock import get_volume_by_price_level

load_dotenv('.env')
UW_API_TOKEN = os.environ.get("UW_API_TOKEN", None)

def main():
    client = UnusualWhalesClient(base_url="https://api.unusualwhales.com", token=UW_API_TOKEN)
    with client as client:
        data: OffLitPriceLevelResults = get_volume_by_price_level.sync(client=client, ticker="SPY", date="2024-05-03")
        for row in data.data:
            rec: OffLitPriceLevel = row
            print(f"${rec.price}: Lit Vol:{decimal(str(rec.lit_vol))} | Dark Vol: {rec.off_vol}")

if __name__ == '__main__':
    main()

API Support

This client supports all api endpoints with exception to websockets.

You can use the openapi.yaml file to generate your own clients for unusual whales in any language openapi has a generator for (and alot exist).

Async Support

This library works with async await to handle non blocking i/o for better performance!

# same code as before but with async/await note that the function changes from sync_detailed to asyncio_detailed
# alternatively you can use sync and asyncio
from unusualwhales.client import UnusualWhalesClient

async with client as client:
    ticker_options_volume: TickerOptionsVolumeResults = await getTickerOptionsVolume.asyncio(client=client,ticker="AAPL",date="2024-05-03")
    for option_volume in ticker_options_volume.data:
        print(option_volume.strike, option_volume.volume)

Things to know:

  1. Every path/method combo becomes a Python module with four functions:

    1. sync: Blocking request that returns parsed data (if successful) or None
    2. sync_detailed: Blocking request that always returns a Request, optionally with parsed set if the request was successful.
    3. asyncio: Like sync but async instead of blocking
    4. asyncio_detailed: Like sync_detailed but async instead of blocking
  2. All path/query params, and bodies become method arguments.

Advanced customizations

There are more settings on the generated Client class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying httpx.Client or httpx.AsyncClient (depending on your use-case):

from unusual_whales_api_client import Client

def log_request(request):
    print(f"Request event hook: {request.method} {request.url} - Waiting for response")

def log_response(response):
    request = response.request
    print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")

client = Client(
    base_url="https://api.unusualwhales.com",
    token="YOUR_API_TOKEN"
    httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
)

Metadata

Release files for unusualwhales-python-client 5.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for unusualwhales-python-client 5.0.1
File Size Uploaded
unusualwhales_python_client-5.0.1.tar.gz 102.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for unusualwhales-python-client 5.0.1
File Interpreter ABI Platform
unusualwhales_python_client-5.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 358.9 kB

Release files / unusualwhales_python_client-5.0.1.tar.gz

Download URL unusualwhales_python_client-5.0.1.tar.gz
Size 102.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ee144ec59092eb2d9aa0417045a24ec5372e55571d584d04464b08c86b45f296
BLAKE2b-256 checksum
How to use checksums
6bb924820fee7edd393de8c26868bf1be042cd78dcad331f6705a155f353f403
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.2 Darwin/23.4.0

Release files / unusualwhales_python_client-5.0.1-py3-none-any.whl

Download URL unusualwhales_python_client-5.0.1-py3-none-any.whl
Size 256.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b8cc235c2785ca73edfb285daa750b8093a86a371e198d3bc82ce0404387566
BLAKE2b-256 checksum
How to use checksums
ea85cbdaf5e175abbd7a4911217586006a577b4ebba17b2af94b8692d10290a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.2 Darwin/23.4.0

Release history Release notifications | RSS feed

This release

5.0.1 This release

2 release files

4.2.3

2 release files

4.2.2

2 release files

4.2.1

2 release files

4.1.1

2 release files

4.0.1

2 release files

3.3

2 release files

3.1

2 release files

3.0

2 release files

2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page