laplace-python-sdk 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.
- laplace_python_sdk-0.1.0/LICENSE +21 -0
- laplace_python_sdk-0.1.0/MANIFEST.in +8 -0
- laplace_python_sdk-0.1.0/PKG-INFO +222 -0
- laplace_python_sdk-0.1.0/README.md +185 -0
- laplace_python_sdk-0.1.0/pyproject.toml +78 -0
- laplace_python_sdk-0.1.0/setup.cfg +4 -0
- laplace_python_sdk-0.1.0/src/laplace/__init__.py +6 -0
- laplace_python_sdk-0.1.0/src/laplace/base.py +119 -0
- laplace_python_sdk-0.1.0/src/laplace/client.py +29 -0
- laplace_python_sdk-0.1.0/src/laplace/collections.py +167 -0
- laplace_python_sdk-0.1.0/src/laplace/financials.py +15 -0
- laplace_python_sdk-0.1.0/src/laplace/funds.py +15 -0
- laplace_python_sdk-0.1.0/src/laplace/li.py +15 -0
- laplace_python_sdk-0.1.0/src/laplace/models.py +210 -0
- laplace_python_sdk-0.1.0/src/laplace/stocks.py +203 -0
- laplace_python_sdk-0.1.0/src/laplace_python_sdk.egg-info/PKG-INFO +222 -0
- laplace_python_sdk-0.1.0/src/laplace_python_sdk.egg-info/SOURCES.txt +18 -0
- laplace_python_sdk-0.1.0/src/laplace_python_sdk.egg-info/dependency_links.txt +1 -0
- laplace_python_sdk-0.1.0/src/laplace_python_sdk.egg-info/requires.txt +13 -0
- laplace_python_sdk-0.1.0/src/laplace_python_sdk.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Laplace
|
|
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.
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: laplace-python-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for Laplace stock data platform
|
|
5
|
+
Author: Laplace SDK Team
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://laplace.finfree.co
|
|
8
|
+
Project-URL: Documentation, https://laplace.finfree.co/en/docs
|
|
9
|
+
Project-URL: Repository, https://github.com/Laplace-Analytics/laplace-python-sdk
|
|
10
|
+
Project-URL: Issues, https://github.com/Laplace-Analytics/laplace-python-sdk/issues
|
|
11
|
+
Keywords: stock,finance,api,sdk,laplace
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: httpx>=0.24.0
|
|
27
|
+
Requires-Dist: pydantic>=2.0.0
|
|
28
|
+
Requires-Dist: typing-extensions>=4.0.0; python_version < "3.10"
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
32
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: isort>=5.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# Laplace Python SDK
|
|
39
|
+
|
|
40
|
+
[](https://badge.fury.io/py/laplace-python-sdk)
|
|
41
|
+
[](https://pypi.org/project/laplace-python-sdk/)
|
|
42
|
+
[](https://opensource.org/licenses/MIT)
|
|
43
|
+
|
|
44
|
+
The official Python SDK for the Laplace stock data platform. Get easy access to stock data, collections, financials, funds, and AI-powered insights.
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
- ๐ **Easy to use**: Simple, intuitive API
|
|
49
|
+
- ๐ **Comprehensive data**: Stocks, collections, financials, funds, and AI insights
|
|
50
|
+
- ๐ง **Well-typed**: Full TypeScript-style typing with Pydantic models
|
|
51
|
+
- ๐งช **Well-tested**: Comprehensive test coverage with real API integration
|
|
52
|
+
- ๐ **Multi-region**: Support for US and Turkish markets
|
|
53
|
+
- โก **Fast**: Built on httpx for high performance
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install laplace-python-sdk
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Quick Start
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from laplace import LaplaceClient
|
|
65
|
+
|
|
66
|
+
# Initialize the client
|
|
67
|
+
client = LaplaceClient(api_key="your-api-key")
|
|
68
|
+
|
|
69
|
+
# Get stock details
|
|
70
|
+
stock = client.stocks.get_detail_by_symbol(symbol="AAPL", region="us")
|
|
71
|
+
print(f"{stock.name}: {stock.description}")
|
|
72
|
+
|
|
73
|
+
# Get all stocks in a region
|
|
74
|
+
stocks = client.stocks.get_all(region="us", page=1, page_size=10)
|
|
75
|
+
for stock in stocks:
|
|
76
|
+
print(f"{stock.symbol}: {stock.name}")
|
|
77
|
+
|
|
78
|
+
# Get collections
|
|
79
|
+
collections = client.collections.get_collections(region="tr", locale="en")
|
|
80
|
+
for collection in collections:
|
|
81
|
+
print(f"{collection.title}: {collection.num_stocks} stocks")
|
|
82
|
+
|
|
83
|
+
# Get collection details
|
|
84
|
+
collection_detail = client.collections.get_collection_detail(
|
|
85
|
+
collection_id="620f455a0187ade00bb0d55f",
|
|
86
|
+
region="tr"
|
|
87
|
+
)
|
|
88
|
+
print(f"Stocks in {collection_detail.title}:")
|
|
89
|
+
for stock in collection_detail.stocks:
|
|
90
|
+
print(f" {stock.symbol}: {stock.name}")
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## API Reference
|
|
94
|
+
|
|
95
|
+
### Stocks Client
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
# Get all stocks with pagination
|
|
99
|
+
stocks = client.stocks.get_all(region="us", page=1, page_size=10)
|
|
100
|
+
|
|
101
|
+
# Get stock detail by symbol
|
|
102
|
+
stock = client.stocks.get_detail_by_symbol(symbol="AAPL", region="us", asset_class="equity")
|
|
103
|
+
|
|
104
|
+
# Get stock detail by ID
|
|
105
|
+
stock = client.stocks.get_detail_by_id(stock_id="stock-id", locale="en")
|
|
106
|
+
|
|
107
|
+
# Get historical prices
|
|
108
|
+
prices = client.stocks.get_price(region="us", symbols=["AAPL", "GOOGL"], keys=["1D", "1W"])
|
|
109
|
+
|
|
110
|
+
# Get historical prices with custom interval
|
|
111
|
+
from datetime import datetime
|
|
112
|
+
from laplace.stocks import HistoricalPriceInterval
|
|
113
|
+
|
|
114
|
+
prices = client.stocks.get_price_with_interval(
|
|
115
|
+
symbol="AAPL",
|
|
116
|
+
region="us",
|
|
117
|
+
from_date=datetime(2024, 1, 1),
|
|
118
|
+
to_date=datetime(2024, 1, 31),
|
|
119
|
+
interval=HistoricalPriceInterval.ONE_DAY
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
# Get tick rules (Turkey only)
|
|
123
|
+
rules = client.stocks.get_tick_rules(region="tr")
|
|
124
|
+
|
|
125
|
+
# Get restrictions (Turkey only)
|
|
126
|
+
restrictions = client.stocks.get_restrictions(region="tr")
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Collections Client
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
# Get all collections
|
|
133
|
+
collections = client.collections.get_collections(region="tr", locale="en")
|
|
134
|
+
|
|
135
|
+
# Get collection detail
|
|
136
|
+
detail = client.collections.get_collection_detail(collection_id="id", region="tr")
|
|
137
|
+
|
|
138
|
+
# Get themes
|
|
139
|
+
themes = client.collections.get_themes(region="tr", locale="en")
|
|
140
|
+
|
|
141
|
+
# Get theme detail
|
|
142
|
+
theme_detail = client.collections.get_theme_detail(theme_id="id", region="tr")
|
|
143
|
+
|
|
144
|
+
# Get industries
|
|
145
|
+
industries = client.collections.get_industries(region="tr", locale="en")
|
|
146
|
+
|
|
147
|
+
# Get industry detail
|
|
148
|
+
industry_detail = client.collections.get_industry_detail(industry_id="id", region="tr")
|
|
149
|
+
|
|
150
|
+
# Get sectors
|
|
151
|
+
sectors = client.collections.get_sectors(region="tr", locale="en")
|
|
152
|
+
|
|
153
|
+
# Get sector detail
|
|
154
|
+
sector_detail = client.collections.get_sector_detail(sector_id="id", region="tr")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Supported Regions
|
|
158
|
+
|
|
159
|
+
- **US**: United States stock market
|
|
160
|
+
- **TR**: Turkey stock market (Borsa Istanbul)
|
|
161
|
+
|
|
162
|
+
## Error Handling
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from laplace import LaplaceClient, LaplaceAPIError
|
|
166
|
+
|
|
167
|
+
client = LaplaceClient(api_key="your-api-key")
|
|
168
|
+
|
|
169
|
+
try:
|
|
170
|
+
stock = client.stocks.get_detail_by_symbol(symbol="INVALID", region="us")
|
|
171
|
+
except LaplaceAPIError as e:
|
|
172
|
+
print(f"API Error: {e}")
|
|
173
|
+
print(f"Status Code: {e.status_code}")
|
|
174
|
+
print(f"Response: {e.response}")
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Authentication
|
|
178
|
+
|
|
179
|
+
Get your API key from the Laplace platform and initialize the client:
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
client = LaplaceClient(api_key="your-api-key-here")
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Development
|
|
186
|
+
|
|
187
|
+
### Setup
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
git clone https://github.com/Laplace-Analytics/laplace-python-sdk.git
|
|
191
|
+
cd laplace-python-sdk
|
|
192
|
+
python -m venv venv
|
|
193
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
194
|
+
pip install -e ".[dev]"
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Running Tests
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
# Run all tests
|
|
201
|
+
pytest
|
|
202
|
+
|
|
203
|
+
# Run with coverage
|
|
204
|
+
pytest --cov=laplace
|
|
205
|
+
|
|
206
|
+
# Run integration tests (requires API key)
|
|
207
|
+
LAPLACE_API_KEY=your-key pytest -m integration
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Requirements
|
|
211
|
+
|
|
212
|
+
- Python 3.8+
|
|
213
|
+
- httpx >= 0.24.0
|
|
214
|
+
- pydantic >= 2.0.0
|
|
215
|
+
|
|
216
|
+
## Documentation
|
|
217
|
+
|
|
218
|
+
Full API documentation is available at [laplace.finfree.co/en/docs](https://laplace.finfree.co/en/docs)
|
|
219
|
+
|
|
220
|
+
## License
|
|
221
|
+
|
|
222
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Laplace Python SDK
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/laplace-python-sdk)
|
|
4
|
+
[](https://pypi.org/project/laplace-python-sdk/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
The official Python SDK for the Laplace stock data platform. Get easy access to stock data, collections, financials, funds, and AI-powered insights.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- ๐ **Easy to use**: Simple, intuitive API
|
|
12
|
+
- ๐ **Comprehensive data**: Stocks, collections, financials, funds, and AI insights
|
|
13
|
+
- ๐ง **Well-typed**: Full TypeScript-style typing with Pydantic models
|
|
14
|
+
- ๐งช **Well-tested**: Comprehensive test coverage with real API integration
|
|
15
|
+
- ๐ **Multi-region**: Support for US and Turkish markets
|
|
16
|
+
- โก **Fast**: Built on httpx for high performance
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install laplace-python-sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from laplace import LaplaceClient
|
|
28
|
+
|
|
29
|
+
# Initialize the client
|
|
30
|
+
client = LaplaceClient(api_key="your-api-key")
|
|
31
|
+
|
|
32
|
+
# Get stock details
|
|
33
|
+
stock = client.stocks.get_detail_by_symbol(symbol="AAPL", region="us")
|
|
34
|
+
print(f"{stock.name}: {stock.description}")
|
|
35
|
+
|
|
36
|
+
# Get all stocks in a region
|
|
37
|
+
stocks = client.stocks.get_all(region="us", page=1, page_size=10)
|
|
38
|
+
for stock in stocks:
|
|
39
|
+
print(f"{stock.symbol}: {stock.name}")
|
|
40
|
+
|
|
41
|
+
# Get collections
|
|
42
|
+
collections = client.collections.get_collections(region="tr", locale="en")
|
|
43
|
+
for collection in collections:
|
|
44
|
+
print(f"{collection.title}: {collection.num_stocks} stocks")
|
|
45
|
+
|
|
46
|
+
# Get collection details
|
|
47
|
+
collection_detail = client.collections.get_collection_detail(
|
|
48
|
+
collection_id="620f455a0187ade00bb0d55f",
|
|
49
|
+
region="tr"
|
|
50
|
+
)
|
|
51
|
+
print(f"Stocks in {collection_detail.title}:")
|
|
52
|
+
for stock in collection_detail.stocks:
|
|
53
|
+
print(f" {stock.symbol}: {stock.name}")
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## API Reference
|
|
57
|
+
|
|
58
|
+
### Stocks Client
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
# Get all stocks with pagination
|
|
62
|
+
stocks = client.stocks.get_all(region="us", page=1, page_size=10)
|
|
63
|
+
|
|
64
|
+
# Get stock detail by symbol
|
|
65
|
+
stock = client.stocks.get_detail_by_symbol(symbol="AAPL", region="us", asset_class="equity")
|
|
66
|
+
|
|
67
|
+
# Get stock detail by ID
|
|
68
|
+
stock = client.stocks.get_detail_by_id(stock_id="stock-id", locale="en")
|
|
69
|
+
|
|
70
|
+
# Get historical prices
|
|
71
|
+
prices = client.stocks.get_price(region="us", symbols=["AAPL", "GOOGL"], keys=["1D", "1W"])
|
|
72
|
+
|
|
73
|
+
# Get historical prices with custom interval
|
|
74
|
+
from datetime import datetime
|
|
75
|
+
from laplace.stocks import HistoricalPriceInterval
|
|
76
|
+
|
|
77
|
+
prices = client.stocks.get_price_with_interval(
|
|
78
|
+
symbol="AAPL",
|
|
79
|
+
region="us",
|
|
80
|
+
from_date=datetime(2024, 1, 1),
|
|
81
|
+
to_date=datetime(2024, 1, 31),
|
|
82
|
+
interval=HistoricalPriceInterval.ONE_DAY
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Get tick rules (Turkey only)
|
|
86
|
+
rules = client.stocks.get_tick_rules(region="tr")
|
|
87
|
+
|
|
88
|
+
# Get restrictions (Turkey only)
|
|
89
|
+
restrictions = client.stocks.get_restrictions(region="tr")
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Collections Client
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
# Get all collections
|
|
96
|
+
collections = client.collections.get_collections(region="tr", locale="en")
|
|
97
|
+
|
|
98
|
+
# Get collection detail
|
|
99
|
+
detail = client.collections.get_collection_detail(collection_id="id", region="tr")
|
|
100
|
+
|
|
101
|
+
# Get themes
|
|
102
|
+
themes = client.collections.get_themes(region="tr", locale="en")
|
|
103
|
+
|
|
104
|
+
# Get theme detail
|
|
105
|
+
theme_detail = client.collections.get_theme_detail(theme_id="id", region="tr")
|
|
106
|
+
|
|
107
|
+
# Get industries
|
|
108
|
+
industries = client.collections.get_industries(region="tr", locale="en")
|
|
109
|
+
|
|
110
|
+
# Get industry detail
|
|
111
|
+
industry_detail = client.collections.get_industry_detail(industry_id="id", region="tr")
|
|
112
|
+
|
|
113
|
+
# Get sectors
|
|
114
|
+
sectors = client.collections.get_sectors(region="tr", locale="en")
|
|
115
|
+
|
|
116
|
+
# Get sector detail
|
|
117
|
+
sector_detail = client.collections.get_sector_detail(sector_id="id", region="tr")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Supported Regions
|
|
121
|
+
|
|
122
|
+
- **US**: United States stock market
|
|
123
|
+
- **TR**: Turkey stock market (Borsa Istanbul)
|
|
124
|
+
|
|
125
|
+
## Error Handling
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from laplace import LaplaceClient, LaplaceAPIError
|
|
129
|
+
|
|
130
|
+
client = LaplaceClient(api_key="your-api-key")
|
|
131
|
+
|
|
132
|
+
try:
|
|
133
|
+
stock = client.stocks.get_detail_by_symbol(symbol="INVALID", region="us")
|
|
134
|
+
except LaplaceAPIError as e:
|
|
135
|
+
print(f"API Error: {e}")
|
|
136
|
+
print(f"Status Code: {e.status_code}")
|
|
137
|
+
print(f"Response: {e.response}")
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Authentication
|
|
141
|
+
|
|
142
|
+
Get your API key from the Laplace platform and initialize the client:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
client = LaplaceClient(api_key="your-api-key-here")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Development
|
|
149
|
+
|
|
150
|
+
### Setup
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
git clone https://github.com/Laplace-Analytics/laplace-python-sdk.git
|
|
154
|
+
cd laplace-python-sdk
|
|
155
|
+
python -m venv venv
|
|
156
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
157
|
+
pip install -e ".[dev]"
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Running Tests
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
# Run all tests
|
|
164
|
+
pytest
|
|
165
|
+
|
|
166
|
+
# Run with coverage
|
|
167
|
+
pytest --cov=laplace
|
|
168
|
+
|
|
169
|
+
# Run integration tests (requires API key)
|
|
170
|
+
LAPLACE_API_KEY=your-key pytest -m integration
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Requirements
|
|
174
|
+
|
|
175
|
+
- Python 3.8+
|
|
176
|
+
- httpx >= 0.24.0
|
|
177
|
+
- pydantic >= 2.0.0
|
|
178
|
+
|
|
179
|
+
## Documentation
|
|
180
|
+
|
|
181
|
+
Full API documentation is available at [laplace.finfree.co/en/docs](https://laplace.finfree.co/en/docs)
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "laplace-python-sdk"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python SDK for Laplace stock data platform"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Laplace SDK Team"}
|
|
14
|
+
]
|
|
15
|
+
keywords = ["stock", "finance", "api", "sdk", "laplace"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.8",
|
|
22
|
+
"Programming Language :: Python :: 3.9",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Topic :: Office/Business :: Financial",
|
|
27
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
28
|
+
]
|
|
29
|
+
dependencies = [
|
|
30
|
+
"httpx>=0.24.0",
|
|
31
|
+
"pydantic>=2.0.0",
|
|
32
|
+
"typing-extensions>=4.0.0; python_version<'3.10'",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
dev = [
|
|
37
|
+
"pytest>=7.0.0",
|
|
38
|
+
"pytest-asyncio>=0.21.0",
|
|
39
|
+
"black>=23.0.0",
|
|
40
|
+
"isort>=5.0.0",
|
|
41
|
+
"mypy>=1.0.0",
|
|
42
|
+
"ruff>=0.1.0",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[project.urls]
|
|
46
|
+
Homepage = "https://laplace.finfree.co"
|
|
47
|
+
Documentation = "https://laplace.finfree.co/en/docs"
|
|
48
|
+
Repository = "https://github.com/Laplace-Analytics/laplace-python-sdk"
|
|
49
|
+
Issues = "https://github.com/Laplace-Analytics/laplace-python-sdk/issues"
|
|
50
|
+
|
|
51
|
+
[tool.setuptools.packages.find]
|
|
52
|
+
where = ["src"]
|
|
53
|
+
|
|
54
|
+
[tool.setuptools.package-dir]
|
|
55
|
+
"" = "src"
|
|
56
|
+
|
|
57
|
+
[tool.black]
|
|
58
|
+
line-length = 100
|
|
59
|
+
target-version = ['py38']
|
|
60
|
+
|
|
61
|
+
[tool.isort]
|
|
62
|
+
profile = "black"
|
|
63
|
+
line_length = 100
|
|
64
|
+
|
|
65
|
+
[tool.mypy]
|
|
66
|
+
python_version = "0.1.0"
|
|
67
|
+
strict = true
|
|
68
|
+
warn_return_any = true
|
|
69
|
+
warn_unused_configs = true
|
|
70
|
+
|
|
71
|
+
[tool.ruff]
|
|
72
|
+
line-length = 100
|
|
73
|
+
target-version = "0.1.0"
|
|
74
|
+
select = ["E", "W", "F", "I", "N", "B", "UP"]
|
|
75
|
+
ignore = ["B008", "N805"]
|
|
76
|
+
|
|
77
|
+
[tool.ruff.isort]
|
|
78
|
+
known-first-party = ["laplace"]
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""Base client for Laplace API."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, Optional, Union
|
|
4
|
+
import httpx
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LaplaceError(Exception):
|
|
9
|
+
"""Base exception for Laplace API errors."""
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class LaplaceAPIError(LaplaceError):
|
|
14
|
+
"""Exception raised for API errors."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, message: str, status_code: Optional[int] = None, response: Optional[Dict[str, Any]] = None):
|
|
17
|
+
super().__init__(message)
|
|
18
|
+
self.status_code = status_code
|
|
19
|
+
self.response = response
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class BaseClient:
|
|
23
|
+
"""Base client for Laplace API communication."""
|
|
24
|
+
|
|
25
|
+
def __init__(self, api_key: str, base_url: str = "https://api.finfree.app/api"):
|
|
26
|
+
"""Initialize the base client.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
api_key: Your Laplace API key
|
|
30
|
+
base_url: Base URL for the API (default: https://api.finfree.app/api)
|
|
31
|
+
"""
|
|
32
|
+
self.api_key = api_key
|
|
33
|
+
self.base_url = base_url.rstrip("/")
|
|
34
|
+
self._client = httpx.Client(
|
|
35
|
+
headers={
|
|
36
|
+
"User-Agent": "laplace-python-sdk/0.1.0",
|
|
37
|
+
},
|
|
38
|
+
timeout=30.0,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
def __enter__(self):
|
|
42
|
+
return self
|
|
43
|
+
|
|
44
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
45
|
+
self.close()
|
|
46
|
+
|
|
47
|
+
def close(self):
|
|
48
|
+
"""Close the HTTP client."""
|
|
49
|
+
self._client.close()
|
|
50
|
+
|
|
51
|
+
def _request(
|
|
52
|
+
self,
|
|
53
|
+
method: str,
|
|
54
|
+
endpoint: str,
|
|
55
|
+
params: Optional[Dict[str, Any]] = None,
|
|
56
|
+
json: Optional[Dict[str, Any]] = None,
|
|
57
|
+
**kwargs
|
|
58
|
+
) -> Dict[str, Any]:
|
|
59
|
+
"""Make a request to the API.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
method: HTTP method
|
|
63
|
+
endpoint: API endpoint (relative to base_url)
|
|
64
|
+
params: Query parameters
|
|
65
|
+
json: JSON body data
|
|
66
|
+
**kwargs: Additional arguments passed to httpx
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
Response data as dictionary
|
|
70
|
+
|
|
71
|
+
Raises:
|
|
72
|
+
LaplaceAPIError: If the API request fails
|
|
73
|
+
"""
|
|
74
|
+
url = f"{self.base_url}/{endpoint.lstrip('/')}"
|
|
75
|
+
|
|
76
|
+
# Add API key to params
|
|
77
|
+
if params is None:
|
|
78
|
+
params = {}
|
|
79
|
+
params["api_key"] = self.api_key
|
|
80
|
+
|
|
81
|
+
try:
|
|
82
|
+
response = self._client.request(
|
|
83
|
+
method=method,
|
|
84
|
+
url=url,
|
|
85
|
+
params=params,
|
|
86
|
+
json=json,
|
|
87
|
+
**kwargs
|
|
88
|
+
)
|
|
89
|
+
response.raise_for_status()
|
|
90
|
+
return response.json()
|
|
91
|
+
except httpx.HTTPStatusError as e:
|
|
92
|
+
try:
|
|
93
|
+
error_data = e.response.json()
|
|
94
|
+
except:
|
|
95
|
+
error_data = {"error": e.response.text}
|
|
96
|
+
|
|
97
|
+
raise LaplaceAPIError(
|
|
98
|
+
message=f"API request failed: {e.response.status_code} {e.response.reason_phrase}",
|
|
99
|
+
status_code=e.response.status_code,
|
|
100
|
+
response=error_data
|
|
101
|
+
) from e
|
|
102
|
+
except httpx.RequestError as e:
|
|
103
|
+
raise LaplaceAPIError(f"Request failed: {str(e)}") from e
|
|
104
|
+
|
|
105
|
+
def get(self, endpoint: str, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
106
|
+
"""Make a GET request."""
|
|
107
|
+
return self._request("GET", endpoint, params=params)
|
|
108
|
+
|
|
109
|
+
def post(self, endpoint: str, json: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
110
|
+
"""Make a POST request."""
|
|
111
|
+
return self._request("POST", endpoint, json=json)
|
|
112
|
+
|
|
113
|
+
def put(self, endpoint: str, json: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
114
|
+
"""Make a PUT request."""
|
|
115
|
+
return self._request("PUT", endpoint, json=json)
|
|
116
|
+
|
|
117
|
+
def delete(self, endpoint: str) -> Dict[str, Any]:
|
|
118
|
+
"""Make a DELETE request."""
|
|
119
|
+
return self._request("DELETE", endpoint)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Main Laplace client."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
from .base import BaseClient
|
|
5
|
+
from .stocks import StocksClient
|
|
6
|
+
from .collections import CollectionsClient
|
|
7
|
+
from .financials import FinancialsClient
|
|
8
|
+
from .funds import FundsClient
|
|
9
|
+
from .li import LaplaceIntelligenceClient
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class LaplaceClient(BaseClient):
|
|
13
|
+
"""Main Laplace API client with all sub-clients."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, api_key: str, base_url: str = "https://api.finfree.app/api"):
|
|
16
|
+
"""Initialize the Laplace client.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
api_key: Your Laplace API key
|
|
20
|
+
base_url: Base URL for the API (default: https://laplace.finfree.co/api)
|
|
21
|
+
"""
|
|
22
|
+
super().__init__(api_key, base_url)
|
|
23
|
+
|
|
24
|
+
# Initialize sub-clients
|
|
25
|
+
self.stocks = StocksClient(self)
|
|
26
|
+
self.collections = CollectionsClient(self)
|
|
27
|
+
self.financials = FinancialsClient(self)
|
|
28
|
+
self.funds = FundsClient(self)
|
|
29
|
+
self.li = LaplaceIntelligenceClient(self)
|