11# node-scraper external plugins (example)
22
33This directory lives at ** ` /docs/node-scraper-external ` ** in the ` node-scraper ` repo and contains
4- an example external plugin package you can install in editable mode.
4+ an example external plugin package that demonstrates how to create plugins for node-scraper.
5+
6+ ## Overview
7+
8+ External plugins are discovered by node-scraper via ** Python entry points** . This allows plugins
9+ to be distributed as separate packages and automatically discovered when installed.
510
611## Installation
712
@@ -12,44 +17,126 @@ cd ~/node-scraper
1217source venv/bin/activate
1318pip install -e ./docs/node-scraper-external
1419```
15- You should see ` ext-nodescraper-plugins ` installed in editable mode.
1620
21+ This installs ` ext-nodescraper-plugins ` in editable mode and registers the plugin entry points.
1722
18- ## Verify the external package is importable
23+ ## Verify Plugin Discovery
24+
25+ Check that node-scraper discovered the external plugin:
1926
2027``` bash
21- python - << 'PY '
22- import ext_nodescraper_plugins
23- print("ext_nodescraper_plugins loaded from:", ext_nodescraper_plugins.__file__)
24- PY
28+ node-scraper run-plugins -h
2529```
2630
27- ## Run external plugins
31+ You should see ` SamplePlugin ` listed alongside built-in plugins.
2832
29- Confirm the CLI sees your external plugin(s):
33+ ## Run the Example Plugin
3034
3135``` bash
32- node-scraper run-plugins -h
3336node-scraper run-plugins SamplePlugin
3437```
3538
36- ## Add your own plugins
39+ ## How It Works
40+
41+ ### Entry Points
3742
38- Add new modules under the ** ` ext_nodescraper_plugins/ ` ** package. Example layout:
43+ Plugins are registered in ` pyproject.toml ` using entry points:
44+
45+ ``` toml
46+ [project .entry-points ."nodescraper .plugins" ]
47+ SamplePlugin = " ext_nodescraper_plugins.sample.sample_plugin:SamplePlugin"
48+ ```
49+
50+ When you install the package, Python registers these entry points in the package metadata.
51+ Node-scraper automatically discovers and loads plugins from the ` nodescraper.plugins ` entry point group.
52+
53+ ### Plugin Structure
3954
4055```
4156/docs/node-scraper-external
42- ├─ pyproject.toml
43- └─ ext_nodescraper_plugins/
44- └─ sample/
57+ ├─ pyproject.toml # Package metadata + entry points
58+ └─ ext_nodescraper_plugins/ # Plugin package
59+ └─ sample/ # Plugin module
4560 ├─ __init__.py
46- └─ sample_plugin.py
61+ ├─ sample_plugin.py # Plugin class
62+ ├─ sample_collector.py # Data collector
63+ ├─ sample_analyzer.py # Data analyzer
64+ └─ sample_data.py # Data model
65+ ```
66+
67+ ## Creating Your Own External Plugins
68+
69+ ### Step 1: Create Package Structure
70+
71+ ``` bash
72+ mkdir my-plugin-package
73+ cd my-plugin-package
74+ mkdir -p ext_nodescraper_plugins/my_plugin
4775```
4876
77+ ### Step 2: Create pyproject.toml
78+
79+ ``` toml
80+ [project ]
81+ name = " my-plugin-package"
82+ version = " 0.1.0"
83+ requires-python = " >=3.10"
84+ dependencies = [" amd-node-scraper" ]
85+
86+ [project .entry-points ."nodescraper .plugins" ]
87+ MyPlugin = " ext_nodescraper_plugins.my_plugin:MyPlugin"
88+
89+ [build-system ]
90+ requires = [" setuptools" , " wheel" ]
91+ build-backend = " setuptools.build_meta"
4992```
5093
51- Re-install (editable mode picks up code changes automatically, but if you add new files you may
52- need to re-run):
94+ ### Step 3: Implement Your Plugin
95+
96+ Create ` ext_nodescraper_plugins/my_plugin/__init__.py ` :
97+
98+ ``` python
99+ from nodescraper.base import InBandDataPlugin, InBandDataCollector
100+ from pydantic import BaseModel
101+
102+ class MyDataModel (BaseModel ):
103+ """ Your data model"""
104+ data: dict
105+
106+ class MyCollector (InBandDataCollector[MyDataModel, None ]):
107+ """ Your data collector"""
108+ DATA_MODEL = MyDataModel
109+
110+ def collect_data (self , args = None ):
111+ # Collection logic
112+ return MyDataModel(data = {})
113+
114+ class MyPlugin (InBandDataPlugin[MyDataModel, None , None ]):
115+ """ Your plugin"""
116+ DATA_MODEL = MyDataModel
117+ COLLECTOR = MyCollector
118+ ```
119+
120+ ### Step 4: Install and Test
121+
53122``` bash
54123pip install -e .
124+ node-scraper run-plugins -h # Should show MyPlugin
125+ node-scraper run-plugins MyPlugin
55126```
127+
128+ ## Adding More Plugins to This Package
129+
130+ To add additional plugins to this example package:
131+
132+ 1 . ** Create a new module** under ` ext_nodescraper_plugins/ `
133+ 2 . ** Register the entry point** in ` pyproject.toml ` :
134+ ``` toml
135+ [project .entry-points ."nodescraper .plugins" ]
136+ SamplePlugin = " ext_nodescraper_plugins.sample.sample_plugin:SamplePlugin"
137+ AnotherPlugin = " ext_nodescraper_plugins.another:AnotherPlugin"
138+ ```
139+ 3 . ** Reinstall** to register the new entry point:
140+ ``` bash
141+ pip install -e . --force-reinstall --no-deps
142+ ```
0 commit comments