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.
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
requestsbeautifulsoup4
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.
- Supported fields:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Setup
- Clone the repository:
git clone https://github.com/yourusername/financial-indexes.git cd financial-indexes
- Create and activate a virtual environment.
- 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
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.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ebec3b03a2a0d1769b62b290475a297905977e464c6a6bfbe780137c3db6fb5
|
|
| MD5 |
64bb72db290cfdb866cb9a876a6734cc
|
|
| BLAKE2b-256 |
dc950cca1be553643c4894af778fff3e37b18556887aebfc4cd2b788987cf6bb
|
Provenance
The following attestation bundles were made for indexes-0.1.0.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.0.tar.gz -
Subject digest:
9ebec3b03a2a0d1769b62b290475a297905977e464c6a6bfbe780137c3db6fb5 - Sigstore transparency entry: 1500820332
- Sigstore integration time:
-
Permalink:
fzunigam/indexes@e69d88d760d67bf399aefca421c0e74646febb4c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/fzunigam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e69d88d760d67bf399aefca421c0e74646febb4c -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b55dc5ea10db79ae40c85149bf4be41f8f171d3676460df471d7f9a1faac7a4
|
|
| MD5 |
138140cb596f673a702e1cf7515413f5
|
|
| BLAKE2b-256 |
48e02c7061593bf30f5726c841a172c4792f749526edb2535a7f907ca851711a
|
Provenance
The following attestation bundles were made for indexes-0.1.0-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.0-py3-none-any.whl -
Subject digest:
5b55dc5ea10db79ae40c85149bf4be41f8f171d3676460df471d7f9a1faac7a4 - Sigstore transparency entry: 1500820432
- Sigstore integration time:
-
Permalink:
fzunigam/indexes@e69d88d760d67bf399aefca421c0e74646febb4c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/fzunigam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e69d88d760d67bf399aefca421c0e74646febb4c -
Trigger Event:
push
-
Statement type: