A lightweight utility to scrape and retrieve financial index constituents, starting with the S&P 500.
Project description
Indexes: A Lightweight S&P 500 Scraper & Financial Data API
indexes is a professional Python utility designed to scrape and retrieve financial index constituents, providing developers with a clean, programmatic interface to access real-time market data. Starting with the S&P 500, it simplifies the process of extracting stock market components for financial analysis and algorithmic trading.
Why use Indexes?
For financial analysts and Python developers, keeping an up-to-date list of S&P 500 constituents can be tedious. indexes provides a simple, cached interface to fetch this data from reliable public sources (like Wikipedia), returning essential metadata such as Sector, Sub-Industry, CIK, and Founded Date.
Key Features
- Efficient S&P 500 Scraper: Get up-to-date SPX constituents in seconds.
- Flexible Data Formats: Retrieve results as a Python
listor adictkeyed by symbol. - Granular Field Selection: Extract only what you need (symbol, name, sector, sub-industry, CIK, etc.).
- Smart Caching: Minimizes network requests by caching data within the same execution session.
- Minimalist Design: Zero-config, lightweight, and easy to integrate into larger financial pipelines.
Installation
Install the package via pip:
pip install indexes
Requirements
- Python >= 3.8
requestsbeautifulsoup4
Quick Start & Usage
from indexes import get_sp500
# Get a simple list of all S&P 500 ticker symbols
symbols = get_sp500()
print(f"Total S&P 500 companies: {len(symbols)}")
# Get detailed company data as a dictionary keyed by ticker symbol
# Perfect for financial modeling and mapping
sp500_details = get_sp500(
return_type='dict',
fields=['name', 'sector', 'sub_industry']
)
# Example: Accessing Apple Inc. metadata
print(sp500_details['AAPL'])
# Output: {'name': 'Apple Inc.', 'sector': 'Information Technology', 'sub_industry': 'Technology Hardware, Storage & Peripherals'}
# Get a list of dictionaries with custom fields
data = get_sp500(return_type='list', fields=['name', 'sector', 'cik'])
API Documentation
get_sp500(return_type='list', fields=None)
The primary entry point for fetching the S&P 500 index components.
return_type(str):'list'(default) or'dict'.fields(list, optional): List of metadata fields to include. Defaults to['symbol'].- Supported fields:
symbol,name,sector,sub_industry,date_added,cik,founded.
- Supported fields:
Development and Contributions
We welcome contributions from the community! Whether it's adding new indexes (Nasdaq 100, Dow Jones) or improving the scraper's robustness, feel free to submit a Pull Request.
Local Setup
- Clone the repository:
git clone https://github.com/fzunigam/indexes.git cd indexes
- Install in editable mode:
pip install -e .
Running Tests
Ensure stability by running the test suite:
pytest
Disclaimer
This project was built with the help of AI coding tools.
License
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file indexes-0.1.1.tar.gz.
File metadata
- Download URL: indexes-0.1.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c573e071a5510a918b295ceb590e01c8048e6a53bd3c54aa61694487971119a
|
|
| MD5 |
f8d6fe9a2433642c3a627666002b341c
|
|
| BLAKE2b-256 |
93383c340dd188650a47356b575a81453af49b1e0471b4faad152ac418d82b59
|
Provenance
The following attestation bundles were made for indexes-0.1.1.tar.gz:
Publisher:
publish.yml on fzunigam/indexes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
indexes-0.1.1.tar.gz -
Subject digest:
0c573e071a5510a918b295ceb590e01c8048e6a53bd3c54aa61694487971119a - Sigstore transparency entry: 1500859878
- Sigstore integration time:
-
Permalink:
fzunigam/indexes@d544b654cbc4a05933a88f1739101dea5016a411 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/fzunigam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d544b654cbc4a05933a88f1739101dea5016a411 -
Trigger Event:
push
-
Statement type:
File details
Details for the file indexes-0.1.1-py3-none-any.whl.
File metadata
- Download URL: indexes-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a6330c20e2d8c290662af1d8b01470706546d044a296a362c7616f17a2ba426
|
|
| MD5 |
dc8c0ad0b3a231b45bff799aa31d7855
|
|
| BLAKE2b-256 |
0ced186cb19a5e0d74d462831d68481f69e58287ca2757c39a9c7118f76f9eab
|
Provenance
The following attestation bundles were made for indexes-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on fzunigam/indexes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
indexes-0.1.1-py3-none-any.whl -
Subject digest:
2a6330c20e2d8c290662af1d8b01470706546d044a296a362c7616f17a2ba426 - Sigstore transparency entry: 1500859883
- Sigstore integration time:
-
Permalink:
fzunigam/indexes@d544b654cbc4a05933a88f1739101dea5016a411 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/fzunigam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d544b654cbc4a05933a88f1739101dea5016a411 -
Trigger Event:
push
-
Statement type: