You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This guide covers preloading Python code that executes during interpreter initialization.
4
+
5
+
## Overview
6
+
7
+
The `py_preload` module allows you to define Python code that runs once per interpreter at creation time. The resulting globals (imports, functions, variables) become available to all process-local environments.
8
+
9
+
## Use Cases
10
+
11
+
- Share common imports across all contexts
12
+
- Define utility functions used throughout your application
13
+
- Set up configuration or constants
14
+
- Avoid repeated initialization overhead
15
+
16
+
## API
17
+
18
+
| Function | Description |
19
+
|----------|-------------|
20
+
|`set_code/1`| Set preload code (binary or iolist) |
21
+
|`get_code/0`| Get current preload code or `undefined`|
22
+
|`clear_code/0`| Remove preload code |
23
+
|`has_preload/0`| Check if preload is configured |
24
+
25
+
## Basic Usage
26
+
27
+
```erlang
28
+
%% Set preload code at application startup
29
+
py_preload:set_code(<<"
30
+
import json
31
+
import os
32
+
33
+
def shared_helper(x):
34
+
return x * 2
35
+
36
+
CONFIG = {'debug': True, 'version': '1.0'}
37
+
">>).
38
+
39
+
%% Create a context - preload is automatically applied
0 commit comments