|
| 1 | +# Python Source Plugin Template |
| 2 | +This repo contains everything you need to get started with building a new plugin. |
| 3 | +To get started all you need to do is change a few names, define some tables, and write an API Client to populate the tables. |
| 4 | + |
| 5 | +## Key files & classes |
| 6 | + - plugin/tables/items.py |
| 7 | + - Items - A boilerplate table definition |
| 8 | + - ItemResolver - A boilerplate table resolver |
| 9 | + - plugin/example/client.py |
| 10 | + - ExampleClient - A boilerplate API Client |
| 11 | + - plugin/client/client.py |
| 12 | + - Spec - Defines the CloudQuery Config |
| 13 | + - Client (uses: ExampleClient) - Wraps your API Client |
| 14 | + - plugin/plugin.py |
| 15 | + - ExamplePlugin - The plugin registration / how CloudQuery knows what tables your plugin exposes. |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +## Getting started |
| 20 | + |
| 21 | +### Defining your tables |
| 22 | +The first thing you need to do is identify the tables you want to create with your plugin. |
| 23 | +Conventionally, CloudQuery plugins have a direct relationship between tables and API responses. |
| 24 | + |
| 25 | +For example: |
| 26 | + If you had an API endpoint https://api.example.com/items/{num} and for each value of `num` it provided an object |
| 27 | + ```json |
| 28 | + { |
| 29 | + "num": {{num}}, |
| 30 | + "date": "2023-10-12", |
| 31 | + "title": "A simple example" |
| 32 | + } |
| 33 | + ``` |
| 34 | + Then you would design the table class as |
| 35 | + ```python |
| 36 | + class Items(Table): |
| 37 | + def __init__(self) -> None: |
| 38 | + super().__init__( |
| 39 | + name="item", |
| 40 | + title="Item", |
| 41 | + columns=[ |
| 42 | + Column("num", pa.uint64(), primary_key=True), |
| 43 | + Column("date", pa.date64()), |
| 44 | + Column("title", pa.string()), |
| 45 | + ], |
| 46 | + ) |
| 47 | + ... |
| 48 | + ``` |
| 49 | + |
| 50 | +Creating one table for each endpoint that you want to capture. |
| 51 | + |
| 52 | +### API Client |
| 53 | +Next you'll need to define how the tables are retrieved, it's recommended to implement this as a generator, as per the example in `plugin/example/client.py`. |
| 54 | + |
| 55 | +### Spec |
| 56 | +Having written your API Client you will have, identified the authentication and/or operational variables needed. |
| 57 | +Adding these to the CloudQuery config spec can be done by editing the `Spec` `dataclass` using standard python, and adding validation where needed. |
| 58 | + |
| 59 | +### Plugin |
| 60 | +Finally, you need to edit the `plugin.py` file to set the plugin name and version, and add the `Tables` to the `get_tables` function. |
| 61 | + |
| 62 | + |
| 63 | +## Links |
| 64 | + |
| 65 | +- [Architecture](https://www.cloudquery.io/docs/developers/architecture) |
| 66 | +- [Concepts](https://www.cloudquery.io/docs/developers/creating-new-plugin/python-source) |
0 commit comments