0
# Core Application Functions
1
2
Essential functions for initializing and running Eel applications, including setup, function exposure, and application lifecycle management.
3
4
## Capabilities
5
6
### Application Initialization
7
8
Initialize Eel with web files directory and configuration options. This must be called before starting the application.
9
10
```python { .api }
11
def init(path: str, allowed_extensions: List[str] = ['.js', '.html', '.txt', '.htm', '.xhtml', '.vue'], js_result_timeout: int = 10000) -> None:
12
"""
13
Initialize Eel with web files directory and configuration.
14
15
Parameters:
16
- path: str - Path to directory containing web files (HTML, CSS, JS)
17
- allowed_extensions: List[str] - File extensions to parse for exposed JS functions
18
- js_result_timeout: int - Timeout in milliseconds for JavaScript function results
19
20
Returns:
21
None
22
"""
23
```
24
25
**Usage Example:**
26
27
```python
28
import eel
29
30
# Initialize with web directory
31
eel.init('web')
32
33
# Initialize with custom configuration
34
eel.init('frontend', allowed_extensions=['.js', '.html', '.vue'], js_result_timeout=5000)
35
```
36
37
### Function Exposure
38
39
Decorator to expose Python functions to JavaScript. Functions can be called from JavaScript with callbacks or async/await.
40
41
```python { .api }
42
def expose(name_or_function: Optional[Callable[..., Any]] = None) -> Callable[..., Any]:
43
"""
44
Decorator to expose Python functions to JavaScript API.
45
46
Parameters:
47
- name_or_function: Optional[Callable] - Function to expose or custom name
48
49
Returns:
50
Callable - Decorated function
51
"""
52
```
53
54
**Usage Examples:**
55
56
```python
57
# Basic exposure
58
@eel.expose
59
def process_data(data):
60
return {"processed": data.upper()}
61
62
# Custom name exposure
63
@eel.expose("customProcessData")
64
def process_data_internal(data):
65
return {"result": data}
66
67
# Expose with string name
68
@eel.expose("my_function")
69
def some_function():
70
pass
71
```
72
73
**JavaScript Usage:**
74
75
```javascript
76
// Call exposed Python function
77
eel.process_data("hello")(function(result) {
78
console.log(result); // {"processed": "HELLO"}
79
});
80
81
// With async/await
82
async function callPython() {
83
const result = await eel.process_data("hello")();
84
console.log(result);
85
}
86
```
87
88
### Application Startup
89
90
Start the Eel application with browser window and web server. This is the main function to launch the application.
91
92
```python { .api }
93
def start(*start_urls: str, mode: Optional[Union[str, Literal[False]]] = 'chrome', host: str = 'localhost', port: int = 8000, block: bool = True, jinja_templates: Optional[str] = None, cmdline_args: List[str] = ['--disable-http-cache'], size: Optional[Tuple[int, int]] = None, position: Optional[Tuple[int, int]] = None, geometry: Dict[str, Tuple[int, int]] = {}, close_callback: Optional[Callable[..., Any]] = None, app_mode: bool = True, all_interfaces: bool = False, disable_cache: bool = True, default_path: str = 'index.html', app: btl.Bottle = btl.default_app(), shutdown_delay: float = 1.0, suppress_error: bool = False) -> None:
94
"""
95
Start the Eel application with browser window.
96
97
Parameters:
98
- *start_urls: str - URLs to open (relative to web directory)
99
- mode: Optional[Union[str, Literal[False]]] - Browser mode ('chrome', 'electron', 'edge', 'custom', False)
100
- host: str - Host for web server
101
- port: int - Port for web server (0 for auto-select)
102
- block: bool - Whether to block calling thread
103
- jinja_templates: Optional[str] - Folder for Jinja2 templates
104
- cmdline_args: List[str] - Command line arguments for browser
105
- size: Optional[Tuple[int, int]] - Window size (width, height)
106
- position: Optional[Tuple[int, int]] - Window position (left, top)
107
- geometry: Dict[str, Tuple[int, int]] - Per-page geometry settings
108
- close_callback: Optional[Callable] - Callback when websocket closes
109
- app_mode: bool - Whether to run in app mode
110
- all_interfaces: bool - Listen on all network interfaces
111
- disable_cache: bool - Disable browser caching
112
- default_path: str - Default file for root URL
113
- app: Bottle - Custom Bottle app instance
114
- shutdown_delay: float - Delay before shutdown detection
115
- suppress_error: bool - Suppress v1.0.0 API change warnings
116
117
Returns:
118
None
119
"""
120
```
121
122
**Usage Examples:**
123
124
```python
125
# Basic startup
126
eel.start('main.html')
127
128
# Custom configuration
129
eel.start('index.html',
130
mode='chrome',
131
size=(1200, 800),
132
position=(100, 100))
133
134
# Multiple URLs
135
eel.start('page1.html', 'page2.html', mode='electron')
136
137
# Non-blocking startup
138
eel.start('app.html', block=False)
139
140
# With close callback
141
def on_close(page, sockets):
142
print(f"Page {page} closed")
143
144
eel.start('main.html', close_callback=on_close)
145
```
146
147
### Show Additional Windows
148
149
Open additional browser windows/tabs after the application has started.
150
151
```python { .api }
152
def show(*start_urls: str) -> None:
153
"""
154
Show specified URLs in browser windows.
155
156
Parameters:
157
- *start_urls: str - URLs to open in browser
158
159
Returns:
160
None
161
"""
162
```
163
164
**Usage Example:**
165
166
```python
167
# Show additional windows
168
eel.show('settings.html')
169
eel.show('help.html', 'about.html')
170
```
171
172
### Custom Bottle Integration
173
174
Register Eel routes with a custom Bottle application instance for advanced middleware integration.
175
176
```python { .api }
177
def register_eel_routes(app: Bottle) -> None:
178
"""
179
Register required Eel routes with custom Bottle app.
180
181
Parameters:
182
- app: Bottle - Bottle application instance
183
184
Returns:
185
None
186
"""
187
```
188
189
**Usage Example:**
190
191
```python
192
import bottle
193
import eel
194
195
# Create custom Bottle app
196
app = bottle.Bottle()
197
198
# Add middleware (e.g., authentication)
199
# ... middleware setup ...
200
201
# Register Eel routes
202
eel.register_eel_routes(app)
203
204
# Start with custom app
205
eel.init('web')
206
eel.start('index.html', app=app)
207
```