indexes 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- indexes-0.1.0/LICENSE +21 -0
- indexes-0.1.0/PKG-INFO +110 -0
- indexes-0.1.0/README.md +89 -0
- indexes-0.1.0/pyproject.toml +32 -0
- indexes-0.1.0/setup.cfg +4 -0
- indexes-0.1.0/src/financial_indexes/__init__.py +4 -0
- indexes-0.1.0/src/financial_indexes/api.py +32 -0
- indexes-0.1.0/src/financial_indexes/scraper.py +26 -0
- indexes-0.1.0/src/indexes.egg-info/PKG-INFO +110 -0
- indexes-0.1.0/src/indexes.egg-info/SOURCES.txt +14 -0
- indexes-0.1.0/src/indexes.egg-info/dependency_links.txt +1 -0
- indexes-0.1.0/src/indexes.egg-info/requires.txt +2 -0
- indexes-0.1.0/src/indexes.egg-info/top_level.txt +1 -0
- indexes-0.1.0/tests/test_api.py +20 -0
- indexes-0.1.0/tests/test_scraper.py +8 -0
- indexes-0.1.0/tests/test_setup.py +4 -0
indexes-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Your Name
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
indexes-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: indexes
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A lightweight utility to scrape and retrieve financial index constituents, starting with the S&P 500.
|
|
5
|
+
Author: Fernando Zuniga
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/fzunigam/indexes
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/fzunigam/indexes/issues
|
|
9
|
+
Keywords: finance,sp500,stock-market,scraping,indexes
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: requests
|
|
19
|
+
Requires-Dist: beautifulsoup4
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# Indexes
|
|
23
|
+
|
|
24
|
+
A lightweight, professional Python utility to scrape and retrieve financial index constituents, starting with the S&P 500.
|
|
25
|
+
|
|
26
|
+
[](LICENSE)
|
|
27
|
+
[](https://pypi.org/project/indexes/)
|
|
28
|
+
[](https://pypi.org/project/indexes/)
|
|
29
|
+
|
|
30
|
+
## About
|
|
31
|
+
|
|
32
|
+
`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.
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
- **Simple API**: Get index data in one function call.
|
|
37
|
+
- **Flexible Output**: Choose between list or dictionary formats.
|
|
38
|
+
- **Selective Fields**: Retrieve only the data you need (symbol, name, sector, etc.).
|
|
39
|
+
- **Automatic Caching**: Minimizes network requests during the same session.
|
|
40
|
+
- **Lightweight**: Minimal dependencies (`requests`, `beautifulsoup4`).
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install indexes
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Requirements
|
|
49
|
+
|
|
50
|
+
- Python >= 3.8
|
|
51
|
+
- `requests`
|
|
52
|
+
- `beautifulsoup4`
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from financial_indexes import get_sp500
|
|
58
|
+
|
|
59
|
+
# Get all S&P 500 symbols as a list
|
|
60
|
+
symbols = get_sp500()
|
|
61
|
+
print(f"Total symbols: {len(symbols)}")
|
|
62
|
+
|
|
63
|
+
# Get detailed info for all companies as a dictionary keyed by symbol
|
|
64
|
+
sp500_details = get_sp500(
|
|
65
|
+
return_type='dict',
|
|
66
|
+
fields=['name', 'sector', 'sub_industry']
|
|
67
|
+
)
|
|
68
|
+
print(sp500_details['AAPL'])
|
|
69
|
+
# Output: {'name': 'Apple Inc.', 'sector': 'Information Technology', 'sub_industry': 'Technology Hardware, Storage & Peripherals'}
|
|
70
|
+
|
|
71
|
+
# Get specific fields as a list of dictionaries
|
|
72
|
+
data = get_sp500(return_type='list', fields=['name', 'sector'])
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Documentation
|
|
76
|
+
|
|
77
|
+
### `get_sp500(return_type='list', fields=None)`
|
|
78
|
+
|
|
79
|
+
Returns constituents of the S&P 500 index.
|
|
80
|
+
|
|
81
|
+
- **`return_type`** (str): `'list'` (default) or `'dict'`.
|
|
82
|
+
- **`fields`** (list, optional): List of fields to include. Defaults to `['symbol']`.
|
|
83
|
+
- Supported fields: `symbol`, `name`, `sector`, `sub_industry`, `date_added`, `cik`, `founded`.
|
|
84
|
+
|
|
85
|
+
## Contributing
|
|
86
|
+
|
|
87
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
88
|
+
|
|
89
|
+
### Development Setup
|
|
90
|
+
|
|
91
|
+
1. Clone the repository:
|
|
92
|
+
```bash
|
|
93
|
+
git clone https://github.com/yourusername/financial-indexes.git
|
|
94
|
+
cd financial-indexes
|
|
95
|
+
```
|
|
96
|
+
2. Create and activate a virtual environment.
|
|
97
|
+
3. Install dependencies:
|
|
98
|
+
```bash
|
|
99
|
+
pip install -e .
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Running Tests
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pytest
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
`financial-indexes` is licensed under the MIT license. See the [`LICENSE`](LICENSE) file for more information.
|
indexes-0.1.0/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Indexes
|
|
2
|
+
|
|
3
|
+
A lightweight, professional Python utility to scrape and retrieve financial index constituents, starting with the S&P 500.
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://pypi.org/project/indexes/)
|
|
7
|
+
[](https://pypi.org/project/indexes/)
|
|
8
|
+
|
|
9
|
+
## About
|
|
10
|
+
|
|
11
|
+
`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.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Simple API**: Get index data in one function call.
|
|
16
|
+
- **Flexible Output**: Choose between list or dictionary formats.
|
|
17
|
+
- **Selective Fields**: Retrieve only the data you need (symbol, name, sector, etc.).
|
|
18
|
+
- **Automatic Caching**: Minimizes network requests during the same session.
|
|
19
|
+
- **Lightweight**: Minimal dependencies (`requests`, `beautifulsoup4`).
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install indexes
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Requirements
|
|
28
|
+
|
|
29
|
+
- Python >= 3.8
|
|
30
|
+
- `requests`
|
|
31
|
+
- `beautifulsoup4`
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from financial_indexes import get_sp500
|
|
37
|
+
|
|
38
|
+
# Get all S&P 500 symbols as a list
|
|
39
|
+
symbols = get_sp500()
|
|
40
|
+
print(f"Total symbols: {len(symbols)}")
|
|
41
|
+
|
|
42
|
+
# Get detailed info for all companies as a dictionary keyed by symbol
|
|
43
|
+
sp500_details = get_sp500(
|
|
44
|
+
return_type='dict',
|
|
45
|
+
fields=['name', 'sector', 'sub_industry']
|
|
46
|
+
)
|
|
47
|
+
print(sp500_details['AAPL'])
|
|
48
|
+
# Output: {'name': 'Apple Inc.', 'sector': 'Information Technology', 'sub_industry': 'Technology Hardware, Storage & Peripherals'}
|
|
49
|
+
|
|
50
|
+
# Get specific fields as a list of dictionaries
|
|
51
|
+
data = get_sp500(return_type='list', fields=['name', 'sector'])
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Documentation
|
|
55
|
+
|
|
56
|
+
### `get_sp500(return_type='list', fields=None)`
|
|
57
|
+
|
|
58
|
+
Returns constituents of the S&P 500 index.
|
|
59
|
+
|
|
60
|
+
- **`return_type`** (str): `'list'` (default) or `'dict'`.
|
|
61
|
+
- **`fields`** (list, optional): List of fields to include. Defaults to `['symbol']`.
|
|
62
|
+
- Supported fields: `symbol`, `name`, `sector`, `sub_industry`, `date_added`, `cik`, `founded`.
|
|
63
|
+
|
|
64
|
+
## Contributing
|
|
65
|
+
|
|
66
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
67
|
+
|
|
68
|
+
### Development Setup
|
|
69
|
+
|
|
70
|
+
1. Clone the repository:
|
|
71
|
+
```bash
|
|
72
|
+
git clone https://github.com/yourusername/financial-indexes.git
|
|
73
|
+
cd financial-indexes
|
|
74
|
+
```
|
|
75
|
+
2. Create and activate a virtual environment.
|
|
76
|
+
3. Install dependencies:
|
|
77
|
+
```bash
|
|
78
|
+
pip install -e .
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Running Tests
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pytest
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
`financial-indexes` is licensed under the MIT license. See the [`LICENSE`](LICENSE) file for more information.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
[project]
|
|
5
|
+
name = "indexes"
|
|
6
|
+
version = "0.1.0"
|
|
7
|
+
description = "A lightweight utility to scrape and retrieve financial index constituents, starting with the S&P 500."
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.8"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "Fernando Zuniga"},
|
|
13
|
+
]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Topic :: Office/Business :: Financial",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
]
|
|
21
|
+
keywords = ["finance", "sp500", "stock-market", "scraping", "indexes"]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"requests",
|
|
24
|
+
"beautifulsoup4",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
"Homepage" = "https://github.com/fzunigam/indexes"
|
|
29
|
+
"Bug Tracker" = "https://github.com/fzunigam/indexes/issues"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools.packages.find]
|
|
32
|
+
where = ["src"]
|
indexes-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from .scraper import fetch_and_parse_sp500
|
|
2
|
+
|
|
3
|
+
SUPPORTED_FIELDS = {'symbol', 'name', 'sector', 'sub_industry', 'date_added', 'cik', 'founded'}
|
|
4
|
+
_CACHE = {}
|
|
5
|
+
|
|
6
|
+
def get_sp500(return_type='list', fields=None):
|
|
7
|
+
if return_type not in ('list', 'dict'):
|
|
8
|
+
raise ValueError("Invalid return_type. Must be 'list' or 'dict'.")
|
|
9
|
+
if fields is None:
|
|
10
|
+
fields = ['symbol']
|
|
11
|
+
for field in fields:
|
|
12
|
+
if field not in SUPPORTED_FIELDS:
|
|
13
|
+
raise ValueError(f"Unsupported field: {field}")
|
|
14
|
+
|
|
15
|
+
if 'sp500' not in _CACHE:
|
|
16
|
+
_CACHE['sp500'] = fetch_and_parse_sp500()
|
|
17
|
+
|
|
18
|
+
data = _CACHE['sp500']
|
|
19
|
+
|
|
20
|
+
if return_type == 'dict':
|
|
21
|
+
return {
|
|
22
|
+
row['symbol']: {k: v for k, v in row.items() if k in fields}
|
|
23
|
+
for row in data
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if return_type == 'list':
|
|
27
|
+
if len(fields) == 1 and fields[0] == 'symbol':
|
|
28
|
+
return [row['symbol'] for row in data]
|
|
29
|
+
return [
|
|
30
|
+
{k: v for k, v in row.items() if k in fields or k == 'symbol'}
|
|
31
|
+
for row in data
|
|
32
|
+
]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from bs4 import BeautifulSoup
|
|
3
|
+
|
|
4
|
+
URL = "https://en.wikipedia.org/wiki/List_of_S%26P_500_companies"
|
|
5
|
+
|
|
6
|
+
def fetch_and_parse_sp500():
|
|
7
|
+
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}
|
|
8
|
+
response = requests.get(URL, headers=headers)
|
|
9
|
+
response.raise_for_status()
|
|
10
|
+
soup = BeautifulSoup(response.text, 'html.parser')
|
|
11
|
+
table = soup.find('table', {'id': 'constituents'})
|
|
12
|
+
|
|
13
|
+
results = []
|
|
14
|
+
for row in table.find_all('tr')[1:]:
|
|
15
|
+
cols = row.find_all(['td', 'th'])
|
|
16
|
+
if len(cols) >= 8:
|
|
17
|
+
results.append({
|
|
18
|
+
'symbol': cols[0].text.strip(),
|
|
19
|
+
'name': cols[1].text.strip(),
|
|
20
|
+
'sector': cols[3].text.strip(),
|
|
21
|
+
'sub_industry': cols[4].text.strip(),
|
|
22
|
+
'date_added': cols[6].text.strip(),
|
|
23
|
+
'cik': cols[7].text.strip(),
|
|
24
|
+
'founded': cols[8].text.strip() if len(cols) > 8 else ''
|
|
25
|
+
})
|
|
26
|
+
return results
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: indexes
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A lightweight utility to scrape and retrieve financial index constituents, starting with the S&P 500.
|
|
5
|
+
Author: Fernando Zuniga
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/fzunigam/indexes
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/fzunigam/indexes/issues
|
|
9
|
+
Keywords: finance,sp500,stock-market,scraping,indexes
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: requests
|
|
19
|
+
Requires-Dist: beautifulsoup4
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# Indexes
|
|
23
|
+
|
|
24
|
+
A lightweight, professional Python utility to scrape and retrieve financial index constituents, starting with the S&P 500.
|
|
25
|
+
|
|
26
|
+
[](LICENSE)
|
|
27
|
+
[](https://pypi.org/project/indexes/)
|
|
28
|
+
[](https://pypi.org/project/indexes/)
|
|
29
|
+
|
|
30
|
+
## About
|
|
31
|
+
|
|
32
|
+
`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.
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
- **Simple API**: Get index data in one function call.
|
|
37
|
+
- **Flexible Output**: Choose between list or dictionary formats.
|
|
38
|
+
- **Selective Fields**: Retrieve only the data you need (symbol, name, sector, etc.).
|
|
39
|
+
- **Automatic Caching**: Minimizes network requests during the same session.
|
|
40
|
+
- **Lightweight**: Minimal dependencies (`requests`, `beautifulsoup4`).
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install indexes
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Requirements
|
|
49
|
+
|
|
50
|
+
- Python >= 3.8
|
|
51
|
+
- `requests`
|
|
52
|
+
- `beautifulsoup4`
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from financial_indexes import get_sp500
|
|
58
|
+
|
|
59
|
+
# Get all S&P 500 symbols as a list
|
|
60
|
+
symbols = get_sp500()
|
|
61
|
+
print(f"Total symbols: {len(symbols)}")
|
|
62
|
+
|
|
63
|
+
# Get detailed info for all companies as a dictionary keyed by symbol
|
|
64
|
+
sp500_details = get_sp500(
|
|
65
|
+
return_type='dict',
|
|
66
|
+
fields=['name', 'sector', 'sub_industry']
|
|
67
|
+
)
|
|
68
|
+
print(sp500_details['AAPL'])
|
|
69
|
+
# Output: {'name': 'Apple Inc.', 'sector': 'Information Technology', 'sub_industry': 'Technology Hardware, Storage & Peripherals'}
|
|
70
|
+
|
|
71
|
+
# Get specific fields as a list of dictionaries
|
|
72
|
+
data = get_sp500(return_type='list', fields=['name', 'sector'])
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Documentation
|
|
76
|
+
|
|
77
|
+
### `get_sp500(return_type='list', fields=None)`
|
|
78
|
+
|
|
79
|
+
Returns constituents of the S&P 500 index.
|
|
80
|
+
|
|
81
|
+
- **`return_type`** (str): `'list'` (default) or `'dict'`.
|
|
82
|
+
- **`fields`** (list, optional): List of fields to include. Defaults to `['symbol']`.
|
|
83
|
+
- Supported fields: `symbol`, `name`, `sector`, `sub_industry`, `date_added`, `cik`, `founded`.
|
|
84
|
+
|
|
85
|
+
## Contributing
|
|
86
|
+
|
|
87
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
88
|
+
|
|
89
|
+
### Development Setup
|
|
90
|
+
|
|
91
|
+
1. Clone the repository:
|
|
92
|
+
```bash
|
|
93
|
+
git clone https://github.com/yourusername/financial-indexes.git
|
|
94
|
+
cd financial-indexes
|
|
95
|
+
```
|
|
96
|
+
2. Create and activate a virtual environment.
|
|
97
|
+
3. Install dependencies:
|
|
98
|
+
```bash
|
|
99
|
+
pip install -e .
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Running Tests
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pytest
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
`financial-indexes` is licensed under the MIT license. See the [`LICENSE`](LICENSE) file for more information.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/financial_indexes/__init__.py
|
|
5
|
+
src/financial_indexes/api.py
|
|
6
|
+
src/financial_indexes/scraper.py
|
|
7
|
+
src/indexes.egg-info/PKG-INFO
|
|
8
|
+
src/indexes.egg-info/SOURCES.txt
|
|
9
|
+
src/indexes.egg-info/dependency_links.txt
|
|
10
|
+
src/indexes.egg-info/requires.txt
|
|
11
|
+
src/indexes.egg-info/top_level.txt
|
|
12
|
+
tests/test_api.py
|
|
13
|
+
tests/test_scraper.py
|
|
14
|
+
tests/test_setup.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
financial_indexes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from financial_indexes.api import get_sp500
|
|
3
|
+
|
|
4
|
+
def test_invalid_return_type():
|
|
5
|
+
with pytest.raises(ValueError, match="Invalid return_type"):
|
|
6
|
+
get_sp500(return_type='tuple')
|
|
7
|
+
|
|
8
|
+
def test_invalid_fields():
|
|
9
|
+
with pytest.raises(ValueError, match="Unsupported field"):
|
|
10
|
+
get_sp500(fields=['symbol', 'fake_field'])
|
|
11
|
+
|
|
12
|
+
def test_get_sp500_list():
|
|
13
|
+
res = get_sp500(return_type='list', fields=['symbol'])
|
|
14
|
+
assert len(res) > 400
|
|
15
|
+
assert isinstance(res[0], str)
|
|
16
|
+
|
|
17
|
+
def test_get_sp500_dict():
|
|
18
|
+
res = get_sp500(return_type='dict', fields=['name'])
|
|
19
|
+
assert 'AAPL' in res
|
|
20
|
+
assert 'name' in res['AAPL']
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from financial_indexes.scraper import fetch_and_parse_sp500
|
|
2
|
+
|
|
3
|
+
def test_scraper_returns_data():
|
|
4
|
+
# Note: in real implementation, mock requests.get, but for this basic setup we test structure
|
|
5
|
+
data = fetch_and_parse_sp500()
|
|
6
|
+
assert isinstance(data, list)
|
|
7
|
+
assert len(data) > 0
|
|
8
|
+
assert 'symbol' in data[0]
|