> ## Documentation Index
> Fetch the complete documentation index at: https://noorle.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Python

> Build a Noorle plugin in Python: componentize-py, uv, generated WASI bindings, and the two-step build that produces a WASI Preview 2 component.

Python reaches WebAssembly through **componentize-py**, which bundles the
interpreter and your module into a single WASI Preview 2 component.

## Prerequisites

* Python 3.10 or newer.
* [`uv`](https://docs.astral.sh/uv/) for dependency management.
* The Noorle CLI.
* The shared WebAssembly tools, installed once with `noorle plugin prepare`.

## Layout

```
weather/
├── app.py             the implementation
├── wit/
│   └── world.wit      the interface — defines your tools
├── pyproject.toml
├── noorle.yaml        metadata, permissions, credentials
├── build.sh           what `noorle plugin build` runs
├── prepare.sh         what `noorle plugin prepare` runs
├── .env.example
└── dist/
    └── plugin.wasm    build output
```

## The interface

The Python world imports the WASI interfaces it needs explicitly — outbound
HTTP and the environment — and exports one function.

```wit theme={"dark"}
package example:weather;

world weather-component {
    // Import WASI HTTP interfaces for making outbound requests
    import wasi:http/types@0.2.7;
    import wasi:http/outgoing-handler@0.2.7;

    // Import for environment variables (to get API key)
    import wasi:cli/environment@0.2.7;

    /// Check the current weather for a location
    export check-weather: func(location: string, unit: string) -> string;
}
```

This example returns a JSON string rather than a WIT `record`, which keeps the
Python side to plain dictionaries.

## The implementation

The build generates a `wit_world` package from your WIT. You subclass the
generated class and implement the exported function as a method.

```python theme={"dark"}
import json
import wit_world

# Generated WASI bindings
from wit_world.imports import types as http_types
from wit_world.imports import outgoing_handler
from wit_world.imports import environment


class WitWorld(wit_world.WitWorld):
    def check_weather(self, location: str, unit: str) -> str:
        # ...
        return json.dumps(result)
```

> [!NOTE]
>
> Outbound HTTP uses the generated WASI bindings directly. `requests` and other
> socket-based clients do not work inside the component — the sandbox exposes
> WASI HTTP and no raw sockets.

Environment variables come from `wasi:cli/environment`, and only the keys
listed under `permissions.environment` are visible.

## `pyproject.toml`

```toml theme={"dark"}
[project]
name = "weather"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = [
    "componentize-py==0.17.2",
]
```

Pure-Python dependencies can be added here. Anything with a compiled extension
will not build for the WASI target.

## `noorle.yaml`

```yaml theme={"dark"}
schema_version: "1.0"

metadata:
  name: weather
  description: "Weather information plugin using OpenWeatherMap API"
  author: "Noorle Team"
  tags:
    - weather
    - api

permissions:
  network:
    allow:
      - host: "api.openweathermap.org"
  environment:
    allow:
      - key: OPENWEATHER_API_KEY
```

Same shape in every language. Full key-by-key reference:
[noorle.yaml](https://noorle.com/docs/build/plugins/configuration.md).

## Build

```bash theme={"dark"}
noorle plugin build
```

That runs the project's `build.sh`, which syncs dependencies, fetches the WIT
dependencies, generates bindings, and then componentizes:

```bash theme={"dark"}
uv sync
wkg wit fetch
uv run componentize-py -d wit/ -w weather-component bindings .
uv run componentize-py -d wit/ -w weather-component componentize app -o dist/plugin.wasm
```

The `bindings` step writes the `wit_world` package your code imports; the
`componentize` step takes the module name (`app`) and emits the component.

## Test locally

```bash theme={"dark"}
wasmtime run --wasi http --env OPENWEATHER_API_KEY=your_api_key_here \
  --invoke 'check-weather("Austin", "metric")' dist/plugin.wasm
```

## Deploy

```bash theme={"dark"}
noorle login
noorle plugin publish
```

## Next

* [Project structure](https://noorle.com/docs/build/plugins/project-structure.md)
* [noorle.yaml reference](https://noorle.com/docs/build/plugins/configuration.md)
* [Permissions](https://noorle.com/docs/build/plugins/permissions.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.