Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex committed Jul 24, 2023
1 parent 67b38a5 commit 8b026e4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
29 changes: 29 additions & 0 deletions docs/integrations/plugins.md
@@ -0,0 +1,29 @@
Pydantic allows users to create plugins that can be used to extend the functionality of the library.

Plugins are installed via Python entry points. You can read more about entry points in the
[Entry points specification](https://packaging.python.org/specifications/entry-points/) from the
Python Packaging Authority.

In case you have a project called `pydantic-plugin`, you can create a plugin by adding the following
to your `pyproject.toml`:

```toml
[project.entry-points.pydantic]
pydantic_plugin = "pydantic_plugin:plugin"
```

The entry point group is `pydantic`, and the name of the entry point is the name of the plugin.

Plugins are loaded in the order they are found, and the order they are found is not guaranteed.

Consider that you have a plugin called `pydantic_plugin`, then you can use it like this:

```py test="skip"
from pydantic import BaseModel

class Foo(BaseModel, pydantic_plugin='all'):
...
```

On each validation call, a callable registered for the event `all` will be called with the
instance of `Foo`, the event name, and the validation result.
1 change: 1 addition & 0 deletions mkdocs.yml
Expand Up @@ -111,6 +111,7 @@ nav:
- 'datamodel-code-generator': integrations/datamodel_code_generator.md
- 'devtools': integrations/devtools.md
- 'Rich': integrations/rich.md
- 'Pydantic Plugins': integrations/plugins.md
- Contribute: contributing.md
- Blog:
- blog/pydantic-v2-final.md
Expand Down
6 changes: 4 additions & 2 deletions pydantic/plugin/loader.py
Expand Up @@ -2,8 +2,10 @@
Plugins are installed via Python entry points, for example in `pyproject.toml`:
[project.entry-points.pydantic]
pydantic_sdk = "pydantic_sdk:main"
```toml
[project.entry-points.pydantic]
pydantic_sdk = "pydantic_sdk:main"
```
The entry point group is `pydantic` and the name of the entry point is the name of the plugin.
Expand Down

0 comments on commit 8b026e4

Please sign in to comment.