Skip to content

Commit 730c5cf

Browse files
authored
Documents submodule example in Python Workers (#25856)
1 parent ddf7796 commit 730c5cf

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/content/docs/workers/languages/python/examples.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,33 @@ Cloudflare has a wide range of Python examples in the [Workers Example gallery](
1111

1212
In addition to those examples, consider the following ones that illustrate Python-specific behavior.
1313

14+
## Modules in your Worker
15+
16+
Let's say your Worker has the following structure:
17+
18+
```
19+
├── src
20+
│   ├── module.py
21+
│   └── main.py
22+
├── uv.lock
23+
├── pyproject.toml
24+
└── wrangler.toml
25+
```
26+
27+
In order to import `module.py` in `main.py`, you would use the following import statement:
28+
29+
```python
30+
import module
31+
```
32+
33+
In this case, the main module is set to `src/main.py` in the wrangler.toml file like so:
34+
35+
```toml
36+
main = "src/main.py"
37+
```
38+
39+
This means that the `src` directory does not need to be specified in the import statement.
40+
1441
## Parse an incoming request URL
1542

1643
```python

0 commit comments

Comments
 (0)