unusualwhales-python-client


Nameunusualwhales-python-client JSON
Version 5.0.1 PyPI version JSON
download
home_pageNone
SummaryA client library for accessing Unusual Whales API
upload_time2024-05-21 23:12:11
maintainerNone
docs_urlNone
authorMac Anderson
requires_python<4.0.0,>=3.10.0
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # unusual-whales-api-client
A client library for accessing Unusual Whales API

Thank you @unusualwhales for providing an excellent api!


## Example Implementation
```python
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!

```python
# 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`
    1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
    1. `asyncio`: Like `sync` but async instead of blocking
    1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking

1. 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):

```python
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]}},
)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "unusualwhales-python-client",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0.0,>=3.10.0",
    "maintainer_email": null,
    "keywords": null,
    "author": "Mac Anderson",
    "author_email": "mac@macanderson.com",
    "download_url": "https://files.pythonhosted.org/packages/6b/b9/24820fee7edd393de8c26868bf1be042cd78dcad331f6705a155f353f403/unusualwhales_python_client-5.0.1.tar.gz",
    "platform": null,
    "description": "# unusual-whales-api-client\nA client library for accessing Unusual Whales API\n\nThank you @unusualwhales for providing an excellent api!\n\n\n## Example Implementation\n```python\nimport os\nimport decimal\nfrom dotenv import load_dotenv\nfrom unusualwhales import UnusualWhalesClient, \n\nfrom unusualwhales.models import OffLitPriceLevelResults, OffLitPriceLevel\nfrom unusualwhales.api.stock import get_volume_by_price_level\n\nload_dotenv('.env')\nUW_API_TOKEN = os.environ.get(\"UW_API_TOKEN\", None)\n\ndef main():\n    client = UnusualWhalesClient(base_url=\"https://api.unusualwhales.com\", token=UW_API_TOKEN)\n    with client as client:\n        data: OffLitPriceLevelResults = get_volume_by_price_level.sync(client=client, ticker=\"SPY\", date=\"2024-05-03\")\n        for row in data.data:\n            rec: OffLitPriceLevel = row\n            print(f\"${rec.price}: Lit Vol:{decimal(str(rec.lit_vol))} | Dark Vol: {rec.off_vol}\")\n\nif __name__ == '__main__':\n    main()\n```\n\n## API Support\nThis client supports all api endpoints with exception to websockets.\n\nYou can use the openapi.yaml file to generate your own clients for unusual whales in\nany language openapi has a generator for (and alot exist).\n\n## Async Support\n\nThis library works with async await to handle non blocking i/o for better performance!\n\n```python\n# same code as before but with async/await note that the function changes from sync_detailed to asyncio_detailed\n# alternatively you can use sync and asyncio\nfrom unusualwhales.client import UnusualWhalesClient\n\nasync with client as client:\n    ticker_options_volume: TickerOptionsVolumeResults = await getTickerOptionsVolume.asyncio(client=client,ticker=\"AAPL\",date=\"2024-05-03\")\n    for option_volume in ticker_options_volume.data:\n        print(option_volume.strike, option_volume.volume)\n```\n\nThings to know:\n1. Every path/method combo becomes a Python module with four functions:\n    1. `sync`: Blocking request that returns parsed data (if successful) or `None`\n    1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.\n    1. `asyncio`: Like `sync` but async instead of blocking\n    1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking\n\n1. All path/query params, and bodies become method arguments.\n\n## Advanced customizations\n\nThere 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):\n\n```python\nfrom unusual_whales_api_client import Client\n\ndef log_request(request):\n    print(f\"Request event hook: {request.method} {request.url} - Waiting for response\")\n\ndef log_response(response):\n    request = response.request\n    print(f\"Response event hook: {request.method} {request.url} - Status {response.status_code}\")\n\nclient = Client(\n    base_url=\"https://api.unusualwhales.com\",\n    token=\"YOUR_API_TOKEN\"\n    httpx_args={\"event_hooks\": {\"request\": [log_request], \"response\": [log_response]}},\n)\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A client library for accessing Unusual Whales API",
    "version": "5.0.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ea85cbdaf5e175abbd7a4911217586006a577b4ebba17b2af94b8692d10290a2",
                "md5": "640e03c1b8b4507c1af34c092f9bcdbb",
                "sha256": "5b8cc235c2785ca73edfb285daa750b8093a86a371e198d3bc82ce0404387566"
            },
            "downloads": -1,
            "filename": "unusualwhales_python_client-5.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "640e03c1b8b4507c1af34c092f9bcdbb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.10.0",
            "size": 256420,
            "upload_time": "2024-05-21T23:12:09",
            "upload_time_iso_8601": "2024-05-21T23:12:09.446747Z",
            "url": "https://files.pythonhosted.org/packages/ea/85/cbdaf5e175abbd7a4911217586006a577b4ebba17b2af94b8692d10290a2/unusualwhales_python_client-5.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6bb924820fee7edd393de8c26868bf1be042cd78dcad331f6705a155f353f403",
                "md5": "392c3b2620b5b8355f366330b0d24100",
                "sha256": "ee144ec59092eb2d9aa0417045a24ec5372e55571d584d04464b08c86b45f296"
            },
            "downloads": -1,
            "filename": "unusualwhales_python_client-5.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "392c3b2620b5b8355f366330b0d24100",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.10.0",
            "size": 102462,
            "upload_time": "2024-05-21T23:12:11",
            "upload_time_iso_8601": "2024-05-21T23:12:11.279980Z",
            "url": "https://files.pythonhosted.org/packages/6b/b9/24820fee7edd393de8c26868bf1be042cd78dcad331f6705a155f353f403/unusualwhales_python_client-5.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-21 23:12:11",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "unusualwhales-python-client"
}
        
Elapsed time: 0.70742s