Skip to content

Commit

Permalink
wip: python plugin example
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric committed Jun 28, 2024
1 parent c22fbc0 commit c32b566
Show file tree
Hide file tree
Showing 42 changed files with 2,859 additions and 0 deletions.
1 change: 1 addition & 0 deletions samples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.wasm
3 changes: 3 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

This directory contains plugins samples for developers.

45 changes: 45 additions & 0 deletions samples/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Python Plugin Sample

This is an example plugin using python.

---
**Documentation**: <a href="https://docs.logcraft.io" target="_blank">https://docs.logcraft.io</a>
---

## Poetry

This example uses python poetry to manage dependencies but feel free to use your prefered package manager.

## Build

Building a plugin is a 2 steps process:

1. Build the bindings for your IDE. This is optional but advised for development.

```bash
poetry run componentize-py --wit-path wit --world plugins bindings myplugin

```

2. Build the plugin. This step automatically build the bindings regardless if you did it in the previous step or not. The resulting wasm file is the LogCraft CLI plugin.

```bash
poetry run componentize-py --wit-path wit --world plugin componentize -p myplugin main -o my-plugin.wasm
```


## Important

As of june 2024, `componentize-py` uses cpython runtime without `zlib`. This is an issue that has consequences: we cannot use python `requests` library and probably others.

This is a known and identified problem that will be fixed in the future by the `componentize-py` team.

To workaround this issue, we created a http library based on `sink`, this is available in this sample python application (`myplugin.client`).


## WIT

The wit files provides from:

1. `wit/world.wit` and `wit/plugin.wit` are LogCraft specific configuration files. These files define input/outputs of plugins.
2. `wit/deps/` come from [wasi-http](https://github.com/WebAssembly/wasi-http/tree/main/wit/deps)
2 changes: 2 additions & 0 deletions samples/python/myplugin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (c) 2023 LogCraft, SAS.
# SPDX-License-Identifier: MPL-2.0
Empty file.
Loading

0 comments on commit c32b566

Please sign in to comment.