Merge branch 'feature/openbb-sdk-v4' of https://github.com/OpenBB-finance/OpenBBTerminal into feature/openbb-sdk-v4

This commit is contained in:
Pratyush Shukla
2023-07-14 01:33:54 +05:30
2 changed files with 89 additions and 11 deletions

33
build/docker/api.dockerfile vendored Normal file
View File

@@ -0,0 +1,33 @@
# ---- Base Python ----
FROM python:3.10-slim-buster AS base
# set work directory
WORKDIR /openbb
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential openssh-client \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# ---- Copy Files/Build ----
FROM base AS builder
WORKDIR /openbb
COPY ./openbb_sdk ./openbb_sdk
# Install the SDK
RUN pip install /openbb/openbb_sdk
# ---- Copy Files ----
FROM base
COPY --from=builder /usr/local /usr/local
# Specify the command to run
CMD ["uvicorn", "openbb_core.api.rest_api:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]

67
openbb_sdk/README.md vendored
View File

@@ -25,7 +25,7 @@ pip install ./openbb-sdk
This will install the SDK and all the dependencies into the site-packages folder of the virtual environment.
When working with the source code of the SDK it is required to create the static python interface:
While we're still developing it is required to create the static python interface:
```python
import openbb
@@ -33,13 +33,21 @@ openbb._rebuild_python_interface()
exit()
```
Right now you need to do this before the first launch and every time you install or uninstall a new extension.
## API keys
To connect to APIs you need to provide the API keys.
To connect to APIs you need to provide the API keys. Here 3 options how you can provide them:
When developing locally you can specify your keys in the `~/.openbb_sdk/user_settings.json`.
1. From local file
2. At runtime
3. From OpenBB Hub
Create this file with the following contents:
### From local file
You can specify the keys from the `~/.openbb_sdk/user_settings.json` file.
Create this file with the following template:
```json
{
@@ -54,16 +62,35 @@ Create this file with the following contents:
Then add your API keys there and it should work.
### From runtime
You can also specify the keys at runtime:
```python
from openbb import obb
openbb.settings.credentials.fmp_api_key = "REPLACE_ME"
openbb.settings.credentials.polygon_api_key = "REPLACE_ME"
```
### From OpenBB Hub
You can also load your the keys from the OpenBB Hub.
```python
from openbb import obb
openbb.account.login(username="REPLACE_ME", password="REPLACE_ME")
```
## Python Usage
Import and basic usage:
```python
from openbb import obb
aapl = obb.stocks.load(symbol="AAPL", start_date="2020-01-01", provider="fmp")
df = aapl.to_dataframe()
df.head()
```
```python
from openbb import obb
aapl = obb.stocks.load(symbol="AAPL", start_date="2020-01-01", provider="fmp")
df = aapl.to_dataframe()
df.head()
```
## API Usage
@@ -77,6 +104,24 @@ Navigate to http://0.0.0.0:8000/docs to see the swagger API documentation.
Authorize with the developer credentials: openbb/openbb
## Docker
You can use the API through docker.
To build the image from the repo root run:
```bash
docker build -f build/docker/api.dockerfile -t openbb-sdk:latest .
```
To run the image:
```bash
docker run --rm -p8000:8000 -v ~/.openbb_sdk:/root/.openbb_sdk openbb-sdk:latest
```
This will mount the local `~/.openbb_sdk` folder into the docker container so you can use the API keys from there and it will expose the API on port 8000.
## Development
From the root of the OpenBB Terminal repo run:
@@ -85,4 +130,4 @@ From the root of the OpenBB Terminal repo run:
When developing a specific extension cd into the extension folder and run:
`poetry install`
`pip install -U -e .`