Skip to content

Commit 9b26fdb

Browse files
authored
chore: Add publishing section to python plugin template (#5)
1 parent 7808f44 commit 9b26fdb

File tree

2 files changed

+51
-36
lines changed

2 files changed

+51
-36
lines changed

README.md

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,75 @@
11
# Python Source Plugin Template
2+
23
This repo contains everything you need to get started with building a new plugin.
34
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.
45

56
[![Mastering CloudQuery: How to build a Source Plugin in Python](https://i.ytimg.com/vi/TSbGHz5Z09M/maxresdefault.jpg)](https://youtu.be/TSbGHz5Z09M "Mastering CloudQuery: How to build a Source Plugin in Python")
67

78
## Key files & classes
8-
- plugin/tables/items.py
9-
- Items - A boilerplate table definition
10-
- ItemResolver - A boilerplate table resolver
11-
- plugin/example/client.py
12-
- ExampleClient - A boilerplate API Client
13-
- plugin/client/client.py
14-
- Spec - Defines the CloudQuery Config
15-
- Client (uses: ExampleClient) - Wraps your API Client
16-
- plugin/plugin.py
17-
- ExamplePlugin - The plugin registration / how CloudQuery knows what tables your plugin exposes.
18-
199

10+
- [plugin/tables/items.py](plugin/tables/items.py)
11+
- `Items` - A boilerplate table definition
12+
- `ItemResolver` - A boilerplate table resolver
13+
- [plugin/example/client.py](plugin/example/client.py)
14+
- `ExampleClient` - A boilerplate API Client
15+
- [plugin/client/client.py]
16+
- `Spec` - Defines the CloudQuery Config
17+
- `Client` (uses: `ExampleClient`) - Wraps your API Client
18+
- [plugin/plugin.py](plugin/plugin.py)
19+
- `ExamplePlugin` - The plugin registration / how CloudQuery knows what tables your plugin exposes.
2020

2121
## Getting started
2222

2323
### Defining your tables
24+
2425
The first thing you need to do is identify the tables you want to create with your plugin.
2526
Conventionally, CloudQuery plugins have a direct relationship between tables and API responses.
2627

2728
For example:
28-
If you had an API endpoint https://api.example.com/items/{num} and for each value of `num` it provided an object
29-
```json
30-
{
31-
"num": {{num}},
32-
"date": "2023-10-12",
33-
"title": "A simple example"
34-
}
35-
```
36-
Then you would design the table class as
37-
```python
38-
class Items(Table):
39-
def __init__(self) -> None:
40-
super().__init__(
41-
name="item",
42-
title="Item",
43-
columns=[
44-
Column("num", pa.uint64(), primary_key=True),
45-
Column("date", pa.date64()),
46-
Column("title", pa.string()),
47-
],
48-
)
49-
...
50-
```
29+
If you had an API endpoint https://api.example.com/items/{num} and for each value of `num` it provided an object
30+
31+
```json
32+
{
33+
"num": {{num}},
34+
"date": "2023-10-12",
35+
"title": "A simple example"
36+
}
37+
```
38+
39+
Then you would design the table class as
40+
41+
```python
42+
class Items(Table):
43+
def __init__(self) -> None:
44+
super().__init__(
45+
name="item",
46+
title="Item",
47+
columns=[
48+
Column("num", pa.uint64(), primary_key=True),
49+
Column("date", pa.date64()),
50+
Column("title", pa.string()),
51+
],
52+
)
53+
...
54+
```
5155

5256
Creating one table for each endpoint that you want to capture.
5357

5458
### API Client
59+
5560
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`.
5661

5762
### Spec
63+
5864
Having written your API Client you will have, identified the authentication and/or operational variables needed.
5965
Adding these to the CloudQuery config spec can be done by editing the `Spec` `dataclass` using standard python, and adding validation where needed.
6066

6167
### Plugin
62-
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.
68+
69+
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.
6370

6471
### Test run
72+
6573
To test your plugin you can run it locally.
6674

6775
To automatically manage your virtual environment and install the dependencies listed in the `pyproject.toml` you can use `poetry`.
@@ -75,6 +83,13 @@ Then to run the plugin `poetry run main serve`, which will launch the plugin man
7583
With that running you can adjust the `TestConfig.yaml` to match your plugin and run `cloudquery sync`.
7684
This should result in the creation of a sqlite database `db.sqlite` where you can validate your tables are as expected.
7785

86+
### Publishing
87+
88+
1. Update the plugin metadata in [plugin/plugin.py](plugin/plugin.py#L13) to match your team and plugin name.
89+
2. Run `python main.py package -m "Initial release" "v0.0.1" .`. `-m` specifies changelog and `v0.0.1` is the version.
90+
3. Run `cloudquery plugin publish -f` to publish the plugin to the CloudQuery registry.
91+
92+
> More about publishing plugins [here](https://docs.cloudquery.io/docs/developers/publishing-an-addon-to-the-hub)
7893
7994
## Links
8095

plugin/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from plugin.client import Client, Spec
1212

1313
PLUGIN_NAME = "example"
14-
PLUGIN_VERSION = "1.0.0" # {x-release-please-version}
14+
PLUGIN_VERSION = "0.0.1"
1515
TEAM_NAME = "cloudquery"
1616
PLUGIN_KIND = "source"
1717

0 commit comments

Comments
 (0)