Skip to main content

Python Implementation for EODHD API

Project description

EODHD-py

An async Python library for downloading financial data from EODHD with intelligent rate limiting. This is an individual project and is not associated with or sponsored by EODHD.

Installation

pip install eodhd-py

Quick Start

import asyncio
from eodhd_py import EodhdApi

async def main():
    # Use demo API key (or set your own)
    async with EodhdApi(api_key="demo") as api:
        # Get end-of-day historical data
        data = await api.eod_historical_api.get_eod_data(symbol="AAPL", interval="d")
        print(f"Retrieved {len(data)} data points")

asyncio.run(main())

Available APIs

Currently the data is always returned as dictionary. A CSV implementation is planned for a future release. Existing EODHD APIs are being added gradually. Below are all the currently available options:

EodHistoricalApi

Provides access to end-of-day historical data. EODHD Documentation

from datetime import datetime
from eodhd_py import EodhdApi

async with EodhdApi(api_key="your_api_key") as api:
    data = await api.eod_historical_api.get_eod_data(
        symbol="AAPL",                      # Stock symbol
        interval="d",                       # "d" (daily), "w" (weekly), "m" (monthly)
        order="a",                          # "a" (ascending), "d" (descending)
        from_date=datetime(2024, 1, 1),     # Optional start date
        to_date=datetime(2024, 12, 31),     # Optional end date
    )

Note: The EODHD API uses period instead of interval. For clarity, we use interval, which gets translated on the backend.

IntradayHistoricalApi

Provides access to intraday historical data. EODHD Documentation

from datetime import datetime
from eodhd_py import EodhdApi

async with EodhdApi(api_key="your_api_key") as api:
    data = await api.intraday_historical_api.get_intraday_data(
        symbol="TSLA",                      # Stock symbol
        interval="5m",                      # "1m", "5m", or "1h"
        from_date=datetime(2024, 1, 1),     # Optional start date
        to_date=datetime(2024, 1, 31),      # Optional end date
        split_dt=False,                     # Split date and time into separate fields
    )

UserApi

Provides access to user account information and API usage statistics. EODHD Documentation

from eodhd_py import EodhdApi

async with EodhdApi(api_key="your_api_key") as api:
    user_info = await api.user_api.get_user_info()
    print(f"Daily limit: {user_info['dailyRateLimit']}")
    print(f"Requests made: {user_info['apiRequests']}")
    print(f"Extra limit: {user_info['extraLimit']}")

Configuration Options

EodhdApiConfig

The config class manages all configuration including sessions, rate limiters, and API limits. For rate limiting, the Steindamm library is used.

Inside the config also lives the session. You can share it between different API classes to avoid opening multiple sessions, simply pass the same config class to different API instance to achieve that.

from eodhd_py import EodhdApi, EodhdApiConfig

config = EodhdApiConfig(
    api_key="your_api_key",              # Required: Your EODHD API key, you can use "demo" for testing (default)
    max_retries=3,                       # Max retries for 429 responses
    daily_max_sleep=3600.0,              # Max wait time for daily limit (seconds)
    minute_max_sleep=120.0,              # Max wait time for minute limit (seconds)
    redis_connection=None,               # Optional Redis connection for distributed limiting
    rate_limit_key=None,                 # Optional unique key for rate limiter naming (max 8 chars)
)

async with EodhdApi(config=config) as api:
    data = await api.eod_historical_api.get_eod_data(symbol="AAPL")

Note: Rate limits are automatically shared between multiple endpoint instances for the same API key, even if the different endpoint instances use completely different configs! You can disable this by passing a unique rate_limit_key when creating the config (max_length=8). As a side-effect, this also means if you create different config classes that use the same API key, the limits should always be the same, otherwise they will conflict. In general, there should never be a case where you need to modify the rate limits since they are fetched from EODHD automatically.

The max_sleep values essentially specify how long the client will wait to make a request. A client will need to wait if the rate limits are currently exhausted. If the time that the client needs to wait exceeds the limit, a steindamm.MaxSleepExceededError is raised. If extra tokens are available in your EODHD subscription, a steindamm.NoTokensAvailableError is returned instead. The defaults can be modified as required, but keep in mind that setting the sleep too high will result in long-hanging clients.

Error Handling

from steindamm import MaxSleepExceededError, NoTokensAvailableError

try:
    async with EodhdApi(api_key="your_api_key") as api: # If no API key is provided "demo" is used
        data = await api.eod_historical_api.get_eod_data(symbol="AAPL")
except MaxSleepExceededError:
    print("Rate limit wait time exceeded configured maximum")
except NoTokensAvailableError:
    print("No API tokens available (extra limit exhausted)")

Note: The library automatically fetches your API limits from the EODHD User API unless explicitly set. It is not recommended to override them, but it can be done if required:

  • daily_calls_rate_limit - Total daily API calls allowed
  • daily_remaining_limit - Remaining daily API calls
  • extra_limit - Additional non-refilling limit if available
  • minute_requests_rate_limit - Requests allowed per minute
  • minute_remaining_limit - Remaining minute requests

Distributed Rate Limiting

Distributed rate limiting is also supported. This means you can download data from the API from multiple clients while not crossing the limits.

from redis.asyncio import Redis  # or from redis.cluster import RedisCluster
from eodhd_py import EodhdApi, EodhdApiConfig

config = EodhdApiConfig(
    api_key="your_api_key",
    redis_connection=Redis.from_url("redis://localhost:6379"),  # Add Redis connection for distributed limiting
)

async with EodhdApi(config=config) as api:
    data = await api.eod_historical_api.get_eod_data(symbol="AAPL")

Important: If the rate limits change (e.g., you buy more requests through the web UI), you need to restart the client or clear the Redis database. The reason is that the rate limit data is stored globally (or in Redis), and there's currently no support for clearing and updating those limits on the fly.

Contributing

Contributions are very welcome. Here's how to get started:

  • Clone the repo
  • Install mise en place
  • Run mise trust to trust the mise.toml file
  • Run mise run install to install dependencies If you prefer not to install mise, check the mise.toml file and run the commands manually, this would also require you to install uv manually.
  • Make your code changes, with tests
  • Run tests with mise run test or uv run pytest
  • Commit your changes and open a PR

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

eodhd_py-0.2.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eodhd_py-0.2.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file eodhd_py-0.2.0.tar.gz.

File metadata

  • Download URL: eodhd_py-0.2.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.4

File hashes

Hashes for eodhd_py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2a9bf20bbb4e55ecdce9ef9dd06b9a6bd622b70a8e8257c1a6853e6f2a1f3c6e
MD5 31d5432b88c8c0ce465b1bb7ad56ab70
BLAKE2b-256 5cc15790e245b664fcb4c294ba31800a8b8e2e8ae6f3036e57bea4da10c976ad

See more details on using hashes here.

File details

Details for the file eodhd_py-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: eodhd_py-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.4

File hashes

Hashes for eodhd_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 66fd61751fcd3697bfc8180fda6bce72aeebcab2e8ced6f820c093d83843132b
MD5 8d3a5f5619f53f917593b3f4410f97b9
BLAKE2b-256 b89232aa6d7946f163f0794f9a53ebb5a1c30e0d6ec4f0503b912715795bb878

See more details on using hashes here.

Supported by

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