Skip to main content

A lightweight utility to scrape and retrieve financial index constituents, starting with the S&P 500.

Project description

Indexes

A lightweight, professional Python utility to scrape and retrieve financial index constituents, starting with the S&P 500.

License PyPI version Python versions

About

indexes provides a simple, cached interface to access up-to-date data for major financial indexes. It currently supports fetching S&P 500 constituents directly from reliable public sources, providing essential metadata like sector, sub-industry, and CIK.

Features

  • Simple API: Get index data in one function call.
  • Flexible Output: Choose between list or dictionary formats.
  • Selective Fields: Retrieve only the data you need (symbol, name, sector, etc.).
  • Automatic Caching: Minimizes network requests during the same session.
  • Lightweight: Minimal dependencies (requests, beautifulsoup4).

Installation

pip install indexes

Requirements

  • Python >= 3.8
  • requests
  • beautifulsoup4

Usage

from financial_indexes import get_sp500

# Get all S&P 500 symbols as a list
symbols = get_sp500()
print(f"Total symbols: {len(symbols)}")

# Get detailed info for all companies as a dictionary keyed by symbol
sp500_details = get_sp500(
    return_type='dict', 
    fields=['name', 'sector', 'sub_industry']
)
print(sp500_details['AAPL'])
# Output: {'name': 'Apple Inc.', 'sector': 'Information Technology', 'sub_industry': 'Technology Hardware, Storage & Peripherals'}

# Get specific fields as a list of dictionaries
data = get_sp500(return_type='list', fields=['name', 'sector'])

Documentation

get_sp500(return_type='list', fields=None)

Returns constituents of the S&P 500 index.

  • return_type (str): 'list' (default) or 'dict'.
  • fields (list, optional): List of fields to include. Defaults to ['symbol'].
    • Supported fields: symbol, name, sector, sub_industry, date_added, cik, founded.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Setup

  1. Clone the repository:
    git clone https://github.com/yourusername/financial-indexes.git
    cd financial-indexes
    
  2. Create and activate a virtual environment.
  3. Install dependencies:
    pip install -e .
    

Running Tests

pytest

License

financial-indexes is licensed under the MIT license. See the LICENSE file for more information.

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

indexes-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

indexes-0.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file indexes-0.1.0.tar.gz.

File metadata

  • Download URL: indexes-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for indexes-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9ebec3b03a2a0d1769b62b290475a297905977e464c6a6bfbe780137c3db6fb5
MD5 64bb72db290cfdb866cb9a876a6734cc
BLAKE2b-256 dc950cca1be553643c4894af778fff3e37b18556887aebfc4cd2b788987cf6bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for indexes-0.1.0.tar.gz:

Publisher: publish.yml on fzunigam/indexes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file indexes-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: indexes-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for indexes-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5b55dc5ea10db79ae40c85149bf4be41f8f171d3676460df471d7f9a1faac7a4
MD5 138140cb596f673a702e1cf7515413f5
BLAKE2b-256 48e02c7061593bf30f5726c841a172c4792f749526edb2535a7f907ca851711a

See more details on using hashes here.

Provenance

The following attestation bundles were made for indexes-0.1.0-py3-none-any.whl:

Publisher: publish.yml on fzunigam/indexes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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