Skip to content

Commit c6922f5

Browse files
committed
docs: fix incorrect method names, defaults, and add missing documentation
- Fix asByteArray() -> asBytes() in basics.md and python-value.md - Add missing methods to python-value.md (raw, isNull, asDoubleMap, asStringMap, etc.) - Fix pool defaults (min: 2->1, max: 8->1), timeout defaults in spring-boot.md - Add missing spring-boot properties (max-code-length, python-executable, warmup-scripts, lenient-warmup) - Fix health check response to match actual PythonEmbedHealthIndicator output - Fix requirements -> requirementsFile in installation.md - Add Extension Properties table to installation.md - Add datetime types to arg() supported list in python-embed.md and basics.md
1 parent a4b040b commit c6922f5

5 files changed

Lines changed: 62 additions & 20 deletions

File tree

docs/api/python-embed.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Creates a `PythonEmbed` with default options.
1313
Creates a `PythonEmbed` with the given options.
1414

1515
### `arg(Object value)`
16-
Converts a Java value to a safe Python literal string. Supports: `null`, `Boolean`, `Number`, `String`, `List`, `Set`, `Map`, `byte[]`, `Instant`.
16+
Converts a Java value to a safe Python literal string. Supports: `null`, `Boolean`, `Number`, `String`, `List`, `Set`, `Map`, `byte[]`, `Instant`, `LocalDateTime`, `LocalDate`, `LocalTime`, `ZonedDateTime`.
1717

1818
## Instance Methods
1919

docs/api/python-value.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@
1515
| `asList(Class<T>)` | `List<T>` | `list` | Convert to typed list |
1616
| `asMap()` | `Map<String, Object>` | `dict` | Convert to raw map |
1717
| `asMap(Class<K>, Class<V>)` | `Map<K, V>` | `dict` | Convert to typed map |
18-
| `asByteArray()` | `byte[]` | `bytes` | Convert to byte array |
18+
| `asBytes()` | `byte[]` | `bytes` | Convert to byte array |
1919
| `toJson()` | `String` | any | JSON string representation |
20+
| `toJson(boolean)` | `String` | any | JSON with optional pretty-print |
21+
| `raw()` | `Object` | any | Get raw Java object |
22+
| `isNull()` | `boolean` | `None` / `null` | Check if value is null |
23+
| `asDoubleMap()` | `Map<String, Double>` | `dict` | Number values as Double |
24+
| `asStringMap()` | `Map<String, String>` | `dict` | String values |
25+
| `asIntMap()` | `Map<String, Integer>` | `dict` | Integer values |
26+
| `asLongMap()` | `Map<String, Long>` | `dict` | Long values |
2027

2128
## Usage Examples
2229

@@ -33,7 +40,7 @@ PythonValue dictVal = py.eval("{'a': 1, 'b': 2}");
3340
Map<String, Integer> map = dictVal.asMap(String.class, Integer.class);
3441

3542
PythonValue bytesVal = py.eval("b'hello'");
36-
byte[] bytes = bytesVal.asByteArray();
43+
byte[] bytes = bytesVal.asBytes();
3744

3845
// JSON serialization
3946
String json = py.eval("{'key': [1, 2, 3]}").toJson();
@@ -43,4 +50,6 @@ String json = py.eval("{'key': [1, 2, 3]}").toJson();
4350

4451
- `asList()` without type parameter returns `List<Object>` — use the typed variant when possible
4552
- `asMap()` without type parameters returns `Map<String, Object>`
53+
- Convenience methods `asDoubleMap()`, `asStringMap()`, `asIntMap()`, `asLongMap()` avoid manual type casting
4654
- `toJson()` serializes the Python value to JSON for logging or transmission
55+
- `toJson(true)` enables pretty-printed output

docs/installation.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pythonEmbed {
2525
'torch',
2626
'msgpack'
2727
]
28-
requirements = file('requirements.txt') // alternative to packages
28+
requirementsFile = 'requirements.txt' // alternative to packages
2929
}
3030
```
3131

@@ -36,6 +36,19 @@ pythonEmbed {
3636
3. If not found → downloads [python-build-standalone](https://github.com/astral-sh/python-build-standalone) (~50 MB, cached) and installs packages directly
3737
4. Packages the venv as a JAR resource for runtime extraction
3838

39+
### Extension Properties
40+
41+
| Property | Type | Default | Description |
42+
|----------|------|---------|-------------|
43+
| `packages` | `List<String>` | `[]` | Pip packages to install |
44+
| `requirementsFile` | `String` || Path to `requirements.txt` (relative to project root) |
45+
| `pyprojectTomlFile` | `String` || Path to `pyproject.toml` (relative to project root) |
46+
| `pythonVersion` | `String` | `3.12` | Python version (for python-build-standalone) |
47+
| `pipIndexUrl` | `String` || Custom pip index URL (e.g., PyTorch CUDA) |
48+
| `pipExtraArgs` | `List<String>` | `[]` | Extra pip install arguments (e.g., `-f`, `--extra-index-url`) |
49+
| `venvOutputDir` | `Directory` | `build/python-venv` | Output directory for the venv |
50+
| `targetOs` | `String` | auto-detected | Cross-compile for `windows`, `linux`, or `macos` |
51+
3952
The venv is rebuilt incrementally — only when dependencies change.
4053

4154
## Spring Boot Starter

docs/spring-boot.md

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,37 @@ management:
9090

9191
Access at `/actuator/health`:
9292

93+
**SINGLE mode:**
94+
9395
```json
9496
{
9597
"status": "UP",
9698
"components": {
9799
"pythonEmbed": {
98100
"status": "UP",
99101
"details": {
100-
"pid": 12345,
101-
"running": true,
102-
"rssMB": 45.2,
102+
"memoryRssKb": 46284,
103103
"refCount": 3,
104-
"gcGen": 1,
105-
"pool": {
106-
"size": 3,
107-
"active": 1,
108-
"minPool": 2,
109-
"maxPool": 8
110-
}
104+
"gcEnabled": true,
105+
"gcCounts": [120, 5, 1]
106+
}
107+
}
108+
}
109+
}
110+
```
111+
112+
**POOL mode:**
113+
114+
```json
115+
{
116+
"status": "UP",
117+
"components": {
118+
"pythonEmbed": {
119+
"status": "UP",
120+
"details": {
121+
"size": 3,
122+
"minPool": 2,
123+
"activeCount": 1
111124
}
112125
}
113126
}
@@ -120,11 +133,15 @@ Access at `/actuator/health`:
120133
|----------|------|---------|-------------|
121134
| `python-embed.mode` | `SINGLE` / `POOL` | `SINGLE` | Bean type to create |
122135
| `python-embed.venv-path` | `String` | auto-resolved | Override venv location |
123-
| `python-embed.pool.min` | `int` | 2 | Minimum pool size |
124-
| `python-embed.pool.max` | `int` | 8 | Maximum pool size |
136+
| `python-embed.pool.min` | `int` | 1 | Minimum pool size |
137+
| `python-embed.pool.max` | `int` | 1 | Maximum pool size |
125138
| `python-embed.pool.idle-timeout` | `Duration` | 60s | Idle instance removal |
126139
| `python-embed.pool.health-check-interval` | `Duration` | 30s | Health ping interval |
127140
| `python-embed.pool.close-timeout` | `Duration` | 30s | Graceful shutdown timeout |
128-
| `python-embed.options.timeout-ms` | `long` | 30000 | Per-request timeout |
129-
| `python-embed.options.startup-timeout-ms` | `long` | 10000 | Process startup timeout |
130-
| `python-embed.options.environment-vars` | `Map` | — | Environment variables |
141+
| `python-embed.options.timeout-ms` | `long` | 0 | Per-request timeout (0 = use PythonEmbed default: 30000) |
142+
| `python-embed.options.startup-timeout-ms` | `long` | 30000 | Process startup timeout |
143+
| `python-embed.options.max-code-length` | `int` | 100000 | Maximum code length in chars |
144+
| `python-embed.options.python-executable` | `String` | — | Override Python executable path |
145+
| `python-embed.options.warmup-scripts` | `List<String>` | — | Warmup scripts to run on startup |
146+
| `python-embed.options.lenient-warmup` | `boolean` | true | Log warmup failures instead of throwing |
147+
| `python-embed.options.environment-vars` | `Map` | — | Environment variables passed to Python process |

docs/usage/basics.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ try (PythonEmbed py = PythonEmbed.create()) {
5454
| `asString()` | `String` | `py.eval("'hi'").asString()` |
5555
| `asList(Class)` | `List<T>` | `py.eval("[1,2,3]").asList(Integer.class)` |
5656
| `asMap(K,V)` | `Map<K,V>` | `py.eval("{'a':1}").asMap(String.class, Integer.class)` |
57-
| `asByteArray()` | `byte[]` | `py.eval("b'\\x01\\x02'").asByteArray()` |
57+
| `asBytes()` | `byte[]` | `py.eval("b'\\x01\\x02'").asBytes()` |
5858
| `toJson()` | `String` | JSON representation |
5959

6060
## arg() — Safe Parameter Injection
@@ -71,6 +71,9 @@ PythonEmbed.arg(List.of(1, 2)); // [1, 2]
7171
PythonEmbed.arg(Set.of(1, 2)); // {1, 2}
7272
PythonEmbed.arg(Map.of("k", 1)); // {'k': 1}
7373
PythonEmbed.arg(new byte[]{1,2}); // b'\x01\x02'
74+
PythonEmbed.arg(LocalDateTime.now()); // datetime.datetime(2024, 1, 15, 10, 30, 0)
75+
PythonEmbed.arg(LocalDate.of(2024, 1, 15)); // datetime.date(2024, 1, 15)
76+
PythonEmbed.arg(Instant.now()); // datetime.datetime.fromtimestamp(...)
7477

7578
// Safe — user input can't break out of the string literal:
7679
String userInput = "Bob'; import os; os.system('rm -rf /') #";

0 commit comments

Comments
 (0)