From 690cde7a6f8468f268286780a650677a8612bc8b Mon Sep 17 00:00:00 2001 From: Theodore Aptekarev Date: Thu, 13 Jul 2023 22:02:22 +0200 Subject: [PATCH] Dockerize the sdk --- build/docker/api.dockerfile | 33 ++++++++++++++++++ openbb_sdk/README.md | 67 +++++++++++++++++++++++++++++++------ 2 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 build/docker/api.dockerfile diff --git a/build/docker/api.dockerfile b/build/docker/api.dockerfile new file mode 100644 index 00000000000..87b876bcdff --- /dev/null +++ b/build/docker/api.dockerfile @@ -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"] diff --git a/openbb_sdk/README.md b/openbb_sdk/README.md index b5543c4baa8..062401cac59 100644 --- a/openbb_sdk/README.md +++ b/openbb_sdk/README.md @@ -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 .`