How to create a class for a Python Table
Steps#
- In the portal go to
settingsand click onBrick Management (v2). - Click the
Create Brickbutton in the topright corner of the screen, or select an existing brick from the list when you need to extend or update an existing brick.
When updating a brick you can choose to make a
Forkfrom an existing brick and build a new brick in the copied fork, orCreate Versionwhich updates the brick to a new version.
- Go to the
codetab and select the file you wish to update or create a new one. - Create a
python classin this file.
Creating the class examples#
The class needs a query method like this:
In this method get the data you wish to create a table from and make sure to return it via:
Where df_2 is the data you wish to create the table from. If there are filters make sure to apply them now, these are created from the WHERE clause in any query.
These methods combined will change the filters into a usable form.
If your data is a pandas DataFrame, you can now filter it easily with
Alternatively you can write your own custom way of filtering your data using the filters.
Using secrets#
If you wish to use secrets you can retrieve them by importing rivendel, and assigning json.loads(rivendel.Secrets.get('brick-secrets', secret_path)) to a variable.