* move old example notebooks to v3 folder, update loadHistoricalPriceData and add findSymbols * Create README.md * Update README.md * Update README.md * Update README.md * Vertical diagram instead * important classes * core dependencies * folder structure * devtools * swap order * fix github pages deploy issue * development index * delete expectations for developers * devtools * obbject stuff * add * installation * hub sync * idk if i committed already * add usage page for financial statements * add link to reference page * syntax * numbers * nearly --> more than * easier to read code blocks * codespell * removing mention to provider * add 'orientation' for to_dict * info card for output user preference * put it in a code block * correct user_settings.json example * syntax corrections * fix sentence * get rid of floating point mathc * get rid of other floating point math * add companion example notebook for financial statements, and new section * historical prices usage page * codespell * add commitment of traders section to usage * add a note * codespell * get rid of equals sign * Cleanup docs. with @the-praxs * install * obbject extend * spell * HeadTitle thingies * Update obbject_extensions.md * Update obbject_extensions.md * typo * Update architectural_considerations.md * point to the TET pattern * optional vs required * reviewing the patterns. removed the --pre flag under the assumption this will be the final docs for the release cc @deeleeramone * add a walkthrough * spelling * Add more in the introduction * validator examples * update Copper-to-Gold notebook example for V4 * Update README.md * QA Caveats w @the-praxs * info on class outputs * merge add data sources and add data points * disclaimer on cookiecutter * add missing import to example * slight syntax change * missing code block * missing import * update intrinio example syntax * intrinio syntax update * urls * core and provider merged * example syntax * grammar * Update API banner link * quick-fix-docs cc @minhhoang1023 * Update pip install command for v3 * remove --pre note block * update landing image --------- Co-authored-by: Henrique Joaquim <h.joaquim@campus.fct.unl.pt> Co-authored-by: Luqman <luqazino@gmail.com> Co-authored-by: James Maslek <jmaslek11@gmail.com> Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com> Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Theodore Aptekarev <aptekarev@gmail.com> Co-authored-by: Pratyush Shukla <ps4534@nyu.edu>
3.2 KiB
Vendored
title, sidebar_position, description, keywords
| title | sidebar_position | description | keywords | ||||
|---|---|---|---|---|---|---|---|
| OBBject Extensions | 8 | This page provides information about how to write extensions for the OpenBB OBBject class. |
|
import HeadTitle from '@site/src/components/General/HeadTitle.tsx';
As mentioned, OpenBB provides some basic methods for interacting with common data structures that will be seen in the results attribute. If you are working with custom data, or adding new endpoints, it is possible that you will want to have your own methods for interacting with the data. The OpenBB Platform provides a way to do this by extending the OBBject class. The architecture for extensions was designed similar to how extensions and accessors are done in pandas, and relies on plugins through the poetry dependency management package.
This page will go through the steps of developing a simple, custom extension for the OBBject class.
Folder structure
example
├── README.md
├── openbb_example
│ └── __init__.py
├── poetry.lock
└── pyproject.toml
Writing the extension
In this example the extension code all lives inside __init__.py.
First we create an Extension class instance to tell openbb-core our extension name and any required credentials to be available at obb.user.credentials.
from openbb_core.app.model.extension import Extension
ext = Extension(name="example", credentials=["some_api_key"])
The credentials are required if the extension uses a key for data or a service, or it can alternatively be connection information for a database, or any other information that needs to be passed to the extension.
Now we define the extension functionality. The decorator @ext.obbject_accessor registers an accessor in each OBBject that is returned when a command is executed. This accessor is just a namespace that will contain the methods defined in the decorated class.
Here, we just add a method to say hi:
@ext.obbject_accessor
class Example:
def __init__(self, obbject):
self._obbject = obbject
def hello(self):
api_key = self._obbject._credentials.some_api_key.get_secret_value()
print(f"Hello, this is my credential: {api_key}!")
Entry Point
The pyproject.toml file will specify the usual setup and dependency information. Additionally, we need to include the following block:
[tool.poetry.plugins."openbb_obbject_extension"]
example = "openbb_example:ext"
With this in the file, we can install the extension by running poetry install from the extension folder.
Using the extension
Now that the extension is installed and built, we can use it! Because we are extending the OBBject, this will be available on any function:
>>> from openbb import obb
>>> obb.user.credentials.some_api_key = "test"
>>> obbject = obb.equity.price.historical("AAPL")
>>> obbject.example.hello()
Hello, this is my credential: test!
In this example, we have added obbject.example as the extension and can use the .hello() functionality right from our OBBject.