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-2.0.tar.gz (101.3 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: unusualwhales_python_client-2.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-2.0.tar.gz
Algorithm Hash digest
SHA256 929ea4616ed21757b5cde084e8cc690a3eb4837a9a8cd46ec683865f839e80e6
MD5 48f34cb8d7ed3eea3a17b8cc71bd2094
BLAKE2b-256 0f3e84504dba942c5a868e63abd834335366ec0ec63320450d603a422f05d4d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for unusualwhales_python_client-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b444f96e844a1eeb2ac8f1906b15fc36cb130ecbe5d9e16ce03c48d3c82ce05
MD5 6805f1b605db8dfa3e1cf4849e8c1b9b
BLAKE2b-256 c02ecde0a531b8aef3d00155cc700fe926a0e71dd1d069a719fea8e05e673ff7

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