pythonhere 0.3.1__tar.gz → 0.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. {pythonhere-0.3.1/pythonhere.egg-info → pythonhere-0.4.1}/PKG-INFO +6 -2
  2. {pythonhere-0.3.1 → pythonhere-0.4.1}/pyproject.toml +9 -1
  3. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/.agents/skills/pythonhere/SKILL.md +5 -1
  4. pythonhere-0.4.1/pythonhere/.agents/skills/pythonhere/references/litert.md +121 -0
  5. pythonhere-0.4.1/pythonhere/.agents/skills/pythonhere/references/tasks.md +58 -0
  6. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/main.py +3 -0
  7. pythonhere-0.4.1/pythonhere/ml_here/__init__.py +17 -0
  8. pythonhere-0.4.1/pythonhere/ml_here/huggingface.py +998 -0
  9. pythonhere-0.4.1/pythonhere/ml_here/storage.py +145 -0
  10. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/server_here.py +1 -0
  11. pythonhere-0.4.1/pythonhere/tasks_here.py +1292 -0
  12. pythonhere-0.4.1/pythonhere/ui_here/connection_address_here.kv +72 -0
  13. pythonhere-0.4.1/pythonhere/version_here.py +1 -0
  14. {pythonhere-0.3.1 → pythonhere-0.4.1/pythonhere.egg-info}/PKG-INFO +6 -2
  15. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere.egg-info/SOURCES.txt +8 -0
  16. pythonhere-0.4.1/pythonhere.egg-info/requires.txt +9 -0
  17. {pythonhere-0.3.1 → pythonhere-0.4.1}/tests/test_main.py +111 -0
  18. pythonhere-0.4.1/tests/test_ml_here.py +416 -0
  19. {pythonhere-0.3.1 → pythonhere-0.4.1}/tests/test_pythonhere_skill.py +4 -1
  20. {pythonhere-0.3.1 → pythonhere-0.4.1}/tests/test_server_here.py +6 -0
  21. pythonhere-0.4.1/tests/test_tasks_here.py +684 -0
  22. pythonhere-0.3.1/pythonhere/ui_here/connection_address_here.kv +0 -32
  23. pythonhere-0.3.1/pythonhere/version_here.py +0 -1
  24. pythonhere-0.3.1/pythonhere.egg-info/requires.txt +0 -4
  25. {pythonhere-0.3.1 → pythonhere-0.4.1}/LICENSE +0 -0
  26. {pythonhere-0.3.1 → pythonhere-0.4.1}/README.rst +0 -0
  27. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/.agents/skills/pythonhere/agents/openai.yaml +0 -0
  28. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/.agents/skills/pythonhere/references/able.md +0 -0
  29. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/.agents/skills/pythonhere/references/android-media.md +0 -0
  30. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/.agents/skills/pythonhere/references/android-packages.md +0 -0
  31. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/.agents/skills/pythonhere/references/android-permissions.md +0 -0
  32. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/.agents/skills/pythonhere/references/android-runtime.md +0 -0
  33. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/.agents/skills/pythonhere/references/jnius.md +0 -0
  34. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/.agents/skills/pythonhere/references/kivy-kv.md +0 -0
  35. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/.agents/skills/pythonhere/references/kivy-runtime.md +0 -0
  36. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/.agents/skills/pythonhere/references/midi.md +0 -0
  37. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/.agents/skills/pythonhere/references/plyer.md +0 -0
  38. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/__init__.py +0 -0
  39. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/android_here.py +0 -0
  40. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/data/logo/logo-128.png +0 -0
  41. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/data/logo/logo-32.png +0 -0
  42. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/data/logo/logo-splash.png +0 -0
  43. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/enum_here.py +0 -0
  44. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/exception_manager_here.kv +0 -0
  45. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/exception_manager_here.py +0 -0
  46. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/launcher_here.py +0 -0
  47. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/magic_here/__init__.py +0 -0
  48. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/magic_here/prompts/README.md +0 -0
  49. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/magic_here/prompts/able.md +0 -0
  50. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/magic_here/prompts/android-media.md +0 -0
  51. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/magic_here/prompts/android-packages.md +0 -0
  52. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/magic_here/prompts/android-permissions.md +0 -0
  53. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/magic_here/prompts/android-runtime.md +0 -0
  54. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/magic_here/prompts/jnius.md +0 -0
  55. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/magic_here/prompts/kivy-kv.md +0 -0
  56. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/magic_here/prompts/kivy-runtime.md +0 -0
  57. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/magic_here/prompts/midi.md +0 -0
  58. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/magic_here/prompts/plyer.md +0 -0
  59. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/magic_here/prompts.py +0 -0
  60. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/magic_here/shortcuts.py +0 -0
  61. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/network_here.py +0 -0
  62. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/patches_here.py +0 -0
  63. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/pythonhere.kv +0 -0
  64. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/tools_here.py +0 -0
  65. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/ui_here/__init__.py +0 -0
  66. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/ui_here/actionbar_here.kv +0 -0
  67. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/ui_here/common_here.kv +0 -0
  68. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/ui_here/connection_address_here.py +0 -0
  69. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/ui_here/layout_here.py +0 -0
  70. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/ui_here/server_screen_here.kv +0 -0
  71. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/ui_here/server_screen_here.py +0 -0
  72. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/ui_here/settings_here.kv +0 -0
  73. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/ui_here/settings_here.py +0 -0
  74. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere/window_here.py +0 -0
  75. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere.egg-info/dependency_links.txt +0 -0
  76. {pythonhere-0.3.1 → pythonhere-0.4.1}/pythonhere.egg-info/top_level.txt +0 -0
  77. {pythonhere-0.3.1 → pythonhere-0.4.1}/setup.cfg +0 -0
  78. {pythonhere-0.3.1 → pythonhere-0.4.1}/setup.py +0 -0
  79. {pythonhere-0.3.1 → pythonhere-0.4.1}/tests/test_ai_prompts.py +0 -0
  80. {pythonhere-0.3.1 → pythonhere-0.4.1}/tests/test_android_here.py +0 -0
  81. {pythonhere-0.3.1 → pythonhere-0.4.1}/tests/test_exception_manager_here.py +0 -0
  82. {pythonhere-0.3.1 → pythonhere-0.4.1}/tests/test_launcher_here.py +0 -0
  83. {pythonhere-0.3.1 → pythonhere-0.4.1}/tests/test_magic.py +0 -0
  84. {pythonhere-0.3.1 → pythonhere-0.4.1}/tests/test_network.py +0 -0
  85. {pythonhere-0.3.1 → pythonhere-0.4.1}/tests/test_patches.py +0 -0
  86. {pythonhere-0.3.1 → pythonhere-0.4.1}/tests/test_settings.py +0 -0
  87. {pythonhere-0.3.1 → pythonhere-0.4.1}/tests/test_tools_here.py +0 -0
  88. {pythonhere-0.3.1 → pythonhere-0.4.1}/tests/test_window_here.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pythonhere
3
- Version: 0.3.1
3
+ Version: 0.4.1
4
4
  Summary: Here is the Kivy based app to run code from the Jupyter magic %there
5
5
  Author-email: b3b <ash.b3b@gmail.com>
6
6
  License-Expression: MIT
@@ -16,10 +16,14 @@ Classifier: Programming Language :: Python :: 3.14
16
16
  Requires-Python: >=3.10
17
17
  Description-Content-Type: text/x-rst
18
18
  License-File: LICENSE
19
- Requires-Dist: herethere[magic]>=0.3.2
19
+ Requires-Dist: herethere[magic]>=0.3.3
20
20
  Requires-Dist: ipython
21
21
  Requires-Dist: ipywidgets
22
22
  Requires-Dist: Pillow
23
+ Requires-Dist: persist-queue==1.1.0
24
+ Provides-Extra: litert
25
+ Requires-Dist: litert-lm-api==0.16.0; extra == "litert"
26
+ Requires-Dist: requests; extra == "litert"
23
27
  Dynamic: license-file
24
28
 
25
29
  PythonHere
@@ -22,10 +22,17 @@ classifiers = [
22
22
  "Programming Language :: Python :: 3.14",
23
23
  ]
24
24
  dependencies = [
25
- "herethere[magic]>=0.3.2",
25
+ "herethere[magic]>=0.3.3",
26
26
  "ipython",
27
27
  "ipywidgets",
28
28
  "Pillow",
29
+ "persist-queue==1.1.0",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ litert = [
34
+ "litert-lm-api==0.16.0",
35
+ "requests",
29
36
  ]
30
37
 
31
38
  [dependency-groups]
@@ -66,6 +73,7 @@ pythonpath = ["pythonhere"]
66
73
  [tool.setuptools]
67
74
  packages = [
68
75
  "pythonhere",
76
+ "pythonhere.ml_here",
69
77
  "pythonhere.magic_here",
70
78
  "pythonhere.ui_here",
71
79
  ]
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: pythonhere
3
- description: "Build, inspect, and debug PythonHere applications by executing Python through the `there` CLI in an already-running Kivy/Python-for-Android process. Use when a task targets a PythonHere device or `there.env` connection and involves live Kivy UI, KV language, Android APIs, Pyjnius, permissions, installed Android packages, media/files, Plyer device features, BLE with able, or MIDI with midistream."
3
+ description: "Build, inspect, and debug PythonHere applications by executing Python through the `there` CLI in an already-running Kivy/Python-for-Android process. Use when a task targets a PythonHere device or `there.env` connection and involves live Kivy UI, KV language, Android APIs, Pyjnius, permissions, installed Android packages, media/files, Plyer device features, BLE with able, MIDI with midistream, durable on-device task runs, or on-device AI with LiteRT-LM and `.litertlm` models."
4
4
  ---
5
5
 
6
6
  # Operate PythonHere with `there`
@@ -40,6 +40,10 @@ when the task depends on it broadly or requires its exact current contents.
40
40
  recording, camera, file selection, GPS, battery, or sensors.
41
41
  - Consult [able.md](references/able.md) for Bluetooth Low Energy work.
42
42
  - Consult [midi.md](references/midi.md) for MIDI or synthesizer work.
43
+ - Consult [litert.md](references/litert.md) for PythonHere's ML model helpers
44
+ and LiteRT-LM usage.
45
+ - Consult [tasks.md](references/tasks.md) for durable sequential work that must
46
+ continue after a client disconnect or recover after PythonHere restarts.
43
47
 
44
48
  Combine references when a feature genuinely needs details from several
45
49
  concerns; for example, an Android gallery may need permission, MediaStore, and
@@ -0,0 +1,121 @@
1
+ # ML model helpers for LiteRT
2
+
3
+ PythonHere provides `ml_here` for acquiring and locating ML model files. It
4
+ does not wrap LiteRT-LM inference.
5
+
6
+ All public model helpers return paths as strings (a list of strings for
7
+ `discover_models()`), ready to pass to `litert_lm.Engine()`.
8
+
9
+ ```python
10
+ from ml_here import (
11
+ discover_models,
12
+ download_hf_model,
13
+ model_path,
14
+ models_directory,
15
+ require_model,
16
+ )
17
+ ```
18
+
19
+ - `models_directory(create=False)` returns PythonHere's model directory. On
20
+ Android this is the app-specific external files directory under `models`; on
21
+ Linux it is `~/.local/share/pythonhere/models`.
22
+ - `model_path(repo_id, filename)` returns the namespaced path for a model. It
23
+ does not create directories and rejects unsafe path components.
24
+ - `require_model(repo_id, filename)` returns that path when the model is
25
+ installed and raises `FileNotFoundError` otherwise.
26
+ - `discover_models(extra_directories=(), extensions=".litertlm")` recursively
27
+ returns sorted, unique LiteRT-LM model paths from managed storage and any
28
+ additional directories. Pass another extension or iterable to select other
29
+ formats, or `extensions=None` to include every completed stored artifact.
30
+ - `download_hf_model(repo_id, filename, *, revision="main", token=None,
31
+ destination=None, progress=None, cancelled=None, overwrite=False,
32
+ expected_sha256=None)` downloads a Hugging Face model file of any format. By
33
+ default, it stores the file at `model_path(repo_id, filename)`.
34
+
35
+ Choose by intent: use `require_model()` to load a known installed model, the
36
+ path returned by `download_hf_model()` after a download, and
37
+ `discover_models()` only to inventory models whose identities are not already
38
+ known. Use `model_path()` when only the expected location is needed.
39
+
40
+ Downloads are resumable across restarts and make the final file visible only
41
+ after the download completes. Cancellation preserves the partial download for
42
+ resuming. Pass a token for private or gated models. The `progress` callback
43
+ receives the following interface; use it directly rather than redefining it:
44
+
45
+ ```python
46
+ class DownloadProgress:
47
+ repo_id: str
48
+ filename: str
49
+ destination: str
50
+ downloaded: int
51
+ total: int | None
52
+ elapsed: float
53
+ speed_bps: float
54
+ fraction: float | None
55
+ percent: float | None
56
+ speed_mbps: float
57
+ remaining: int | None
58
+ eta: float | None
59
+ ```
60
+
61
+ Use `litert_lm` directly to load and run the returned model path.
62
+
63
+ ## Run an installed model
64
+
65
+ Run model loading and inference on a worker (`--worker`) to keep Kivy
66
+ responsive. In the app runtime, import model helpers from `ml_here`.
67
+
68
+ ```python
69
+ import litert_lm
70
+ from ml_here import require_model
71
+
72
+ model_file = require_model(
73
+ "litert-community/SmolLM2-135M-Instruct",
74
+ "SmolLM2_135M_Instruct.litertlm",
75
+ )
76
+ engine = litert_lm.Engine(model_file)
77
+ try:
78
+ with engine.create_conversation(max_output_tokens=128) as conversation:
79
+ response = conversation.send_message(
80
+ "What is the Kivy framework? Answer in one short paragraph."
81
+ )
82
+ text = "".join(
83
+ part["text"]
84
+ for part in response["content"]
85
+ if part.get("type") == "text"
86
+ )
87
+ print(text)
88
+ finally:
89
+ engine.close()
90
+ ```
91
+
92
+ The conversation closes before the engine, including when inference raises.
93
+ For an interactive chat, keep the engine loaded and reuse the conversation
94
+ for follow-up messages; close both when the chat is finished.
95
+
96
+ `litert_lm.Engine(model_file)` uses CPU by default. For a model and device
97
+ that support GPU inference, replace the engine construction above with:
98
+
99
+ ```python
100
+ engine = litert_lm.Engine(model_file, backend=litert_lm.Backend.GPU())
101
+ ```
102
+
103
+ ## Download first when needed
104
+
105
+ If the model is not installed, download it on a worker before inference:
106
+
107
+ ```python
108
+ from ml_here import download_hf_model
109
+
110
+ model_file = download_hf_model(
111
+ "litert-community/SmolLM2-135M-Instruct",
112
+ "SmolLM2_135M_Instruct.litertlm",
113
+ )
114
+ print(model_file)
115
+ ```
116
+
117
+ When downloading and loading in the same script, pass the returned
118
+ `model_file` directly to `litert_lm.Engine()`.
119
+
120
+ See the [upstream Python API](https://github.com/google-ai-edge/LiteRT-LM/tree/main/python)
121
+ for streaming, sampling, and multimodal inference.
@@ -0,0 +1,58 @@
1
+ # Durable task runs
2
+
3
+ Use `TaskRunner` for sequential work that must continue after the client
4
+ disconnects, retain progress across a PythonHere restart, or retry individual
5
+ items.
6
+
7
+ ## Start a run
8
+
9
+ ```python
10
+ from tasks_here import TaskRunner
11
+
12
+ runner = TaskRunner.create("data-import", max_attempts=3)
13
+ runner.add([
14
+ {"id": "part-1", "path": "one.json"},
15
+ {"id": "part-2", "path": "two.json"},
16
+ ])
17
+ runner.start(execute_task)
18
+ ```
19
+
20
+ Tasks and results must contain plain JSON-compatible values. Every task needs a
21
+ unique nonempty string `id`. `start()` returns promptly and processes one task
22
+ at a time. Preserve the runner in a named global when later commands need it.
23
+
24
+ Inspect `runner.status()`, `runner.results()`, `runner.get(id)`, or
25
+ `runner.failed()` through normal `there get` calls. `pause()` finishes the
26
+ current item and stops before claiming another.
27
+
28
+ ## Wait and inspect the outcome
29
+
30
+ After starting the runner, wait in bounded intervals through the CLI:
31
+
32
+ ```bash
33
+ there --json --timeout 60 get --worker \
34
+ "{'stopped': runner.wait(timeout=50), 'status': runner.status()}"
35
+ ```
36
+
37
+ Here, `--worker` keeps the wait off the app's event loop.
38
+ Keep the CLI timeout longer than the wait timeout to allow time for connection
39
+ and response. If `stopped` is `false`, tasks continue running; repeat the command
40
+ to wait again. A `true` value only means the worker is no longer running (or was
41
+ never started), not that every task succeeded. Inspect `status.state`,
42
+ `status.failed`, and `status.worker_error`. A `completed` state includes tasks
43
+ that exhausted their retries; inspect `runner.failed()` for their errors.
44
+
45
+ ## Resume after restart
46
+
47
+ After PythonHere restarts, reopen the named run, recreate resources and the
48
+ executor callable, then restart execution:
49
+
50
+ ```python
51
+ runner = TaskRunner.open("data-import")
52
+ runner.start(execute_task)
53
+ ```
54
+
55
+ Execution is at least once: an item interrupted by process death can run again.
56
+ Make irreversible executor side effects idempotent or check their durable state
57
+ before applying them. The executor runs in a background thread; marshal Kivy UI
58
+ access to the main thread according to `kivy-runtime.md`.
@@ -26,6 +26,7 @@ from kivy.app import App
26
26
  from kivy.clock import Clock
27
27
  from kivy.config import Config, ConfigParser
28
28
  from kivy.logger import Logger
29
+ from kivy.properties import StringProperty # pylint: disable=no-name-in-module
29
30
  from patches_here import monkeypatch_kivy
30
31
  from server_here import run_ssh_server
31
32
  from window_here import reset_window_environment
@@ -42,6 +43,8 @@ def configure_logging():
42
43
  class PythonHereApp(App):
43
44
  """PythonHere main app."""
44
45
 
46
+ ssh_host_key_sha256 = StringProperty("")
47
+
45
48
  def __init__(self):
46
49
  super().__init__()
47
50
  self.server_task: asyncio.Task | None = None
@@ -0,0 +1,17 @@
1
+ """Acquire, store, index, and discover ML model files for PythonHere."""
2
+
3
+ from .huggingface import download_hf_model
4
+ from .storage import (
5
+ discover_models,
6
+ model_path,
7
+ models_directory,
8
+ require_model,
9
+ )
10
+
11
+ __all__ = (
12
+ "discover_models",
13
+ "download_hf_model",
14
+ "model_path",
15
+ "models_directory",
16
+ "require_model",
17
+ )