Skip to main content

A library to for https://alpha.isnow.ai

Project description

alpha-isnow

alpha-isnow is a Python library to load daily asset data (Stocks, ETFs, Indices, and Cryptocurrencies) from Cloudflare R2 and merge them into a single Pandas DataFrame. The library:

  • Lists parquet files stored under bucket_name/ds/<repo_id>/*.parquet for each asset.
  • Validates that the monthly slices (files named as YYYY.MM.parquet) are continuous with no missing months.
  • Supports loading data concurrently using a configurable number of threads (default is 4).
  • Uses Python's built-in logging module to log messages to the console (default level is ERROR).

Installation

When you install alpha-isnow via pip, its dependencies (pandas, s3fs, boto3) will be automatically installed. To install the package:

pip install alpha-isnow

Usage

from alpha.datasets import load_daily, AssetType

# Load all available months of stock data
df = load_daily(
    asset_type=AssetType.Stocks,
    token={  # Optional, defaults to environment variables
        "R2_ENDPOINT_URL": "your-r2-endpoint",
        "R2_ACCESS_KEY_ID": "your-access-key",
        "R2_SECRET_ACCESS_KEY": "your-secret-key",
    }
)

# Load a specific range of months
df_range = load_daily(
    asset_type=AssetType.ETFs, 
    month_range=("2023.01", "2023.03")
)

print(f"Loaded {len(df)} records")

Function Parameters

The load_daily function accepts the following parameters:

  • asset_type (AssetType): The type of asset to load (Stocks, ETFs, Indices, or Cryptocurrencies)
  • month_range (tuple[str, str] | None): Optional tuple (start, end) with month strings in 'YYYY.MM' format. If None, loads all available months
  • symbols (list[str] | None): Optional list of symbols to load. If None, loads all available symbols. If sp500 is in the list, it will be removed and SP500 symbols will be added.
  • threads (int): Number of threads to use for concurrent loading (default: 4)
  • adjust (bool): Whether to adjust prices using the adjustment factor (default: True)
  • to_usd (bool): Whether to convert prices to USD (default: True)
    • For Forex: Inverts exchange rates (e.g., EURUSD becomes USDEUR)
    • For Indices: Converts to USD using corresponding currency exchange rates
  • rate_to_price (bool): For Bonds, whether to convert interest rates to prices (default: True)
  • token (dict | None): Optional dictionary containing R2 credentials:
    {
        "R2_ENDPOINT_URL": "your-r2-endpoint",
        "R2_ACCESS_KEY_ID": "your-access-key",
        "R2_SECRET_ACCESS_KEY": "your-secret-key"
    }
    
    If None, environment variables are used
  • cache (bool): Whether to use local caching for improved performance (default: False)

The package uses a namespace package structure, so even though the package name is alpha-isnow, you import it with from alpha.datasets import ...

Development

Installation for Development

For development, install the package in editable mode with development dependencies:

pip install -e ".[dev]"

This will install:

  • Runtime dependencies (pandas, s3fs, boto3, pyarrow)
  • Development tools:
    • pytest: For running tests
    • black: For code formatting
    • isort: For import sorting
    • mypy: For type checking
    • flake8: For code quality checks
    • build: For building distribution packages
    • twine: For uploading to PyPI

Building and Releasing

To build distribution packages:

# Build both wheel and source distribution
python -m build

# The packages will be created in the dist/ directory

To release to PyPI:

# Upload to PyPI (requires PyPI credentials)
python -m twine upload dist/*

# Or upload to TestPyPI first (recommended for first-time releases)
python -m twine upload --repository testpypi dist/*

Note: You only need to upload the latest version. PyPI will maintain the version history automatically.

To upload a specific version:

# Upload specific version files
python -m twine upload dist/alpha_isnow-<version>

# Or upload to TestPyPI
python -m twine upload --repository testpypi dist/alpha_isnow-<version>

PyPI Configuration

Before uploading to PyPI, you need to configure your credentials. Create or edit ~/.pypirc file:

[pypi]
username = __token__
password = your-pypi-token

[testpypi]
username = __token__
password = your-testpypi-token

Replace your-pypi-token and your-testpypi-token with your actual PyPI and TestPyPI tokens. You can generate these tokens from your PyPI account settings.

Local Cache

The library implements a local caching mechanism to improve data loading performance:

  • Cache location: ~/.alpha_isnow_cache/
  • Cache format: Parquet files named as {repo_name}_{month}.parquet
  • Cache validity: 24 hours
  • Performance: Loading from cache is typically 100x faster than loading from R2

Running Tests

# Run all tests
pytest tests/

# Run specific test file
pytest tests/test_loader.py

# Run tests with verbose output
pytest -v tests/test_loader.py

Code Quality

The project follows Python best practices:

  • Code formatting with black
  • Import sorting with isort
  • Type checking with mypy
  • Code quality checks with flake8

All code changes should pass these checks before being committed.

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

alpha_isnow-0.1.6.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

alpha_isnow-0.1.6-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file alpha_isnow-0.1.6.tar.gz.

File metadata

  • Download URL: alpha_isnow-0.1.6.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for alpha_isnow-0.1.6.tar.gz
Algorithm Hash digest
SHA256 6e9830ef51c1719daac46b73508aa5cf3d44bc06437d74fd0674e1a6aef148dc
MD5 7850dd41c12b56db69dbaf86766db13a
BLAKE2b-256 bd07922554a63409a7e883b3cee47a05f635c5bc8ecdd9f07ca19da7c1210a46

See more details on using hashes here.

File details

Details for the file alpha_isnow-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: alpha_isnow-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for alpha_isnow-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b54a06ee9ac9622fb0a9dcea920f3fa62027012e266babbc4db6722fd66efb7c
MD5 9bc2a7ded20621605f9cf282ddbc9af1
BLAKE2b-256 aa586c03256af37616e67fef5b1626800281fa0537f9fc33967de95afbff6437

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