Skip to main content

A client library for accessing Unusual Whales API

Project description

unusual-whales-api-client

A client library for accessing Unusual Whales API

Thank you @unusualwhales for providing an excellent api and for leaving your openapi schema unobfuscated from the network logs on your api documentation website :->)

For feature requests email mac@macanderson.com - I do not provide support

Importing Modules

You can import modules using the following syntax:

from unusualwhales.client import Client from unusualwhales.api.[tag] import [function] from unusualwhales.models import [ModelNameHere] from unusualwhales.types import Response

import os
from dotenv import load_dotenv
from unusualwhales.client import AuthenticatedClient
from unusualwhales.api.[tag] import [function]
from unusualwhales.models import [ModelNameHere]
from unusualwhales.types import Response

load_dotenv('/path/to/.env')
# This app requires an api token to included when initializing a new AuthenticatedClient
# you can use python-dotenv as shown here to save it in a .env file so that you
# do not have unsecured code
API_TOKEN = os.environ.get("UNUSUAL_WHALES_API_TOKEN", None)

client = AuthenticatedClient(base_url="https://api.unusualwhales.com", token=API_TOKEN)
import os

from dotenv import load_dotenv

from unusualwhales.client import AuthenticatedClient
from unusualwhales.models import TickerOptionsVolume
from unusualwhales.api.stock import getTickerOptionsVolume
from unusualwhales.types import Response

load_dotenv('/path/to/.env')
API_TOKEN = os.environ.get("UNUSUAL_WHALES_API_TOKEN", None)

client = AuthenticatedClient(base_url="https://api.unusualwhales.com", token=API_TOKEN)
with client as client:
    ticker_options_volume: Response[TickerOptionsVolume] = getTickerOptionsVolume.sync(client=client,ticker="AAPL",date="2024-05-03")
    for option_volume in ticker_options_volume:
        print(option_volume.strike, option_volume.volume)

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 AuthenticatedClient

async with client as client:
    ticker_options_volume: TickerOptionsVolume = await getTickerOptionsVolume.asyncio(client=client,ticker="AAPL",date="2024-05-03")
    for option_volume in ticker_options_volume:
        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",
    httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unusualwhales_python_client-3.0.tar.gz (101.3 kB view details)

Uploaded Source

Built Distribution

unusualwhales_python_client-3.0-py3-none-any.whl (255.3 kB view details)

Uploaded Python 3

File details

Details for the file unusualwhales_python_client-3.0.tar.gz.

File metadata

  • Download URL: unusualwhales_python_client-3.0.tar.gz
  • Upload date:
  • Size: 101.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Darwin/23.4.0

File hashes

Hashes for unusualwhales_python_client-3.0.tar.gz
Algorithm Hash digest
SHA256 c77c4d43f787a92a179a557ef3de9e8d8511a5ccb1f98f36a61e69fd36a08d22
MD5 7c5f0aff283c51203a0dc6f9fe8126c1
BLAKE2b-256 f069f98c774f5de903a9a8a397694aa1cc79c90db1b9c1e8338764b2f80202c2

See more details on using hashes here.

File details

Details for the file unusualwhales_python_client-3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for unusualwhales_python_client-3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b4443ef92f0bbdcd118f0b11b469208eb801c23790dbae7f84a20f662a0da76
MD5 f86b8a73ade6b8efaba87fa43407a5f4
BLAKE2b-256 fddbd6b555e0a45cba116fa7a4d04feb6cee217484b7a46749289ca956278367

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page