* fix circular import issues on the obbject extension framework * settings available on the obbject * extension init * charting assets and code * introduce to_chart functionality * removes the to_chart method from obbject in detriment of the one from the obbject extension * Update openbb_platform/obbject_extensions/charting/charting/__init__.py Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> * fix on the show method * adding the example to the to_chart docstring * copying the exsting README from charting extension - needs to be revamped * moving to openbb_charting instead * update the pyproject.toml file * pydocstyle * versions * better docstrings * making accessors public * removing unnecessary credentials variable cc @montezdesousa * removing access to extra/metadata and use designated private attrs instead * Fixes linting for the logging service (#5992) * lints * typing.Type instead * deprecating ChartingService to use the new extension instead - adding function discovery capabilities using it * tests for the obbject charting extension * removing charting service from command runner * filter functions not implemented in the module * remove charting service tests * removing charting service on the tests for int tests * charting integration tests * removing charting service file * removing old charting extension code * revamp builder * fix obbject tests * fix command_runner tests * removing openbb_figure_table * better website docs * reviewed readme * unsetting api key for posthog (pywry) windows * added debug_mode to the system settings * removing api key * update nightly script * fix tests * black * black * Revert "black" This reverts commit21d76ad689. * Revert "black" This reverts commit0904653fd7. * black for henrique * returning a list instead * better docstrings * removing unnecessary indicators docstring * typo * black * intentional access to protected member * changes to publish script * filtering deleted files * black * adding render argument * fixing the df_to_basemodel function: it should include the index in the columns either if flagged or if the index is named * adding the hability to add you own data to to_chart method * tests * black * disable protected access * accept kwargs to eg. save image * adjustment cc Igor * add if statement for protection * remove unused return typing * fix technical charting views * better error message cc @IgorWounds * better structure and fix test * Revert "better structure and fix test" This reverts commit612ea6117c. * Revert "better error message cc @IgorWounds" This reverts commit3d7ee53878. --------- Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com> Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com>
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._user_settings.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.