-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathextism.pyi
164 lines (127 loc) · 4.29 KB
/
extism.pyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# WARNING THIS FILE IS AI GENERATED from
# https://github.com/extism/python-pdk/blob/main/lib/src/prelude.py and
# https://github.com/extism/python-pdk/blob/main/lib/src/py_module.rs
# It is meant purely for developer/IDE usage and should not be made available to
# extism-py
#
# Prompt used with Claude 3.5 Sonnet:
# `prelude.py` defines an `extism` module. Generate a dummy module (`.pyi`) for
# `extism` so IDEs can understand. Be sure to preserve the original comments.
"""
Extism Python Plugin Development Kit (PDK)
This module provides the interface for developing Extism plugins in Python.
It includes functionality for handling plugin I/O, HTTP requests, memory management,
configuration, and host function interactions.
"""
from typing import Any, TypeVar, Callable, Optional, Union, Dict, List, Type, TypeAlias, overload
from enum import Enum
class LogLevel(Enum):
Trace: LogLevel
Debug: LogLevel
Info: LogLevel
Warn: LogLevel
Error: LogLevel
class MemoryHandle:
offset: int
length: int
def __init__(self, offset: int, length: int) -> None: ...
class memory:
@staticmethod
def find(offs: int) -> Optional[MemoryHandle]: ...
@staticmethod
def bytes(mem: MemoryHandle) -> bytes: ...
@staticmethod
def string(mem: MemoryHandle) -> str: ...
@staticmethod
def free(mem: MemoryHandle) -> None: ...
@staticmethod
def alloc(data: bytes) -> MemoryHandle: ...
class HttpRequest:
url: str
method: Optional[str]
headers: Optional[Dict[str, str]]
def __init__(self, url: str, method: Optional[str] = None, headers: Optional[Dict[str, str]] = None) -> None: ...
class _HttpResponseInternal:
def status_code(self) -> int: ...
def data(self) -> bytes: ...
headers: Dict[str, str]
class HttpResponse:
_inner: _HttpResponseInternal
def __init__(self, res: _HttpResponseInternal) -> None: ...
@property
def status_code(self) -> int:
"""Get HTTP status code"""
...
def data_bytes(self) -> bytes:
"""Get response body bytes"""
...
def data_str(self) -> str:
"""Get response body string"""
...
def data_json(self) -> Any:
"""Get response body JSON"""
...
def headers(self) -> Dict[str, str]:
"""Get HTTP response headers"""
...
class Http:
@staticmethod
def request(
url: str,
meth: str = "GET",
body: Optional[Union[bytes, str]] = None,
headers: Optional[Dict[str, str]] = None
) -> HttpResponse:
"""Make an HTTP request"""
...
T = TypeVar('T')
def log(level: LogLevel, msg: Union[str, bytes, Any]) -> None: ...
def input_bytes() -> bytes: ...
def output_bytes(result: bytes) -> None: ...
def input_str() -> str: ...
def output_str(result: str) -> None: ...
def import_fn(module: str, name: str) -> Callable[[Callable[..., Any]], Callable[..., Any]]:
"""Annotate an import function"""
...
def plugin_fn(func: Callable[[], Any]) -> Callable[[], Any]:
"""Annotate a function that will be called by Extism"""
...
def shared_fn(f: Callable[..., Any]) -> Callable[..., Any]:
"""Annotate a an export that won't be called directly by Extism"""
...
def input_json(t: Optional[Type[T]] = None) -> Union[T, Any]:
"""Get input as JSON"""
...
def output_json(x: Any) -> None:
"""Set JSON output"""
...
def input(t: Optional[Type[T]] = None) -> Optional[T]:
...
def output(x: Optional[Union[str, bytes, Dict[str, Any], List[Any], Enum]] = None) -> None:
...
class Var:
@staticmethod
def get_bytes(key: str) -> Optional[bytes]:
"""Get variable as bytes"""
...
@staticmethod
def get_str(key: str) -> Optional[str]:
"""Get variable as string"""
...
@staticmethod
def get_json(key: str) -> Optional[Any]:
"""Get variable as JSON"""
...
@staticmethod
def set(key: str, value: Union[bytes, str]) -> None:
"""Set a variable with a string or bytes value"""
...
class Config:
@staticmethod
def get_str(key: str) -> Optional[str]:
"""Get a config value as string"""
...
@staticmethod
def get_json(key: str) -> Optional[Any]:
"""Get a config value as JSON"""
...