mrmd-python 0.1.0__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.
- mrmd_python-0.1.0/.gitignore +44 -0
- mrmd_python-0.1.0/PKG-INFO +77 -0
- mrmd_python-0.1.0/README.md +47 -0
- mrmd_python-0.1.0/pyproject.toml +50 -0
- mrmd_python-0.1.0/src/mrmd_python/__init__.py +16 -0
- mrmd_python-0.1.0/src/mrmd_python/cli.py +119 -0
- mrmd_python-0.1.0/src/mrmd_python/server.py +609 -0
- mrmd_python-0.1.0/src/mrmd_python/types.py +245 -0
- mrmd_python-0.1.0/src/mrmd_python/worker.py +1525 -0
- mrmd_python-0.1.0/uv.lock +599 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
|
|
23
|
+
# Virtual environments
|
|
24
|
+
.venv/
|
|
25
|
+
venv/
|
|
26
|
+
ENV/
|
|
27
|
+
|
|
28
|
+
# IDE
|
|
29
|
+
.idea/
|
|
30
|
+
.vscode/
|
|
31
|
+
*.swp
|
|
32
|
+
*.swo
|
|
33
|
+
|
|
34
|
+
# Testing
|
|
35
|
+
.pytest_cache/
|
|
36
|
+
.coverage
|
|
37
|
+
htmlcov/
|
|
38
|
+
|
|
39
|
+
# Runtime assets (generated)
|
|
40
|
+
.mrmd-assets/
|
|
41
|
+
|
|
42
|
+
# OS
|
|
43
|
+
.DS_Store
|
|
44
|
+
Thumbs.db
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mrmd-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python runtime server implementing the MRMD Runtime Protocol (MRP)
|
|
5
|
+
Author: mrmd contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: ipython,mrmd,mrp,notebook,runtime
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Requires-Dist: black>=25.12.0
|
|
18
|
+
Requires-Dist: ipython>=8.0.0
|
|
19
|
+
Requires-Dist: jedi>=0.19.0
|
|
20
|
+
Requires-Dist: sse-starlette>=2.0.0
|
|
21
|
+
Requires-Dist: starlette>=0.40.0
|
|
22
|
+
Requires-Dist: uvicorn>=0.32.0
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: httpx>=0.27.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
27
|
+
Provides-Extra: format
|
|
28
|
+
Requires-Dist: black>=24.0.0; extra == 'format'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# mrmd-python
|
|
32
|
+
|
|
33
|
+
Python runtime server implementing the MRMD Runtime Protocol (MRP).
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
uv pip install mrmd-python
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
### Command Line
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
mrmd-python --port 8000
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Programmatic
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from mrmd_python import create_app
|
|
53
|
+
import uvicorn
|
|
54
|
+
|
|
55
|
+
app = create_app(cwd="/path/to/project")
|
|
56
|
+
uvicorn.run(app, host="localhost", port=8000)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## API Endpoints
|
|
60
|
+
|
|
61
|
+
All endpoints are prefixed with `/mrp/v1/`.
|
|
62
|
+
|
|
63
|
+
| Endpoint | Method | Purpose |
|
|
64
|
+
|----------|--------|---------|
|
|
65
|
+
| `/capabilities` | GET | Runtime capabilities |
|
|
66
|
+
| `/sessions` | GET/POST | List/create sessions |
|
|
67
|
+
| `/execute` | POST | Run code |
|
|
68
|
+
| `/execute/stream` | POST | Run code with SSE streaming |
|
|
69
|
+
| `/complete` | POST | Get completions |
|
|
70
|
+
| `/inspect` | POST | Get symbol info |
|
|
71
|
+
| `/hover` | POST | Get hover tooltip |
|
|
72
|
+
| `/variables` | POST | List variables |
|
|
73
|
+
| `/interrupt` | POST | Cancel execution |
|
|
74
|
+
|
|
75
|
+
## Protocol
|
|
76
|
+
|
|
77
|
+
See [PROTOCOL.md](../mrmd-editor/PROTOCOL.md) for the full MRP specification.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# mrmd-python
|
|
2
|
+
|
|
3
|
+
Python runtime server implementing the MRMD Runtime Protocol (MRP).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
uv pip install mrmd-python
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Command Line
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
mrmd-python --port 8000
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Programmatic
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from mrmd_python import create_app
|
|
23
|
+
import uvicorn
|
|
24
|
+
|
|
25
|
+
app = create_app(cwd="/path/to/project")
|
|
26
|
+
uvicorn.run(app, host="localhost", port=8000)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## API Endpoints
|
|
30
|
+
|
|
31
|
+
All endpoints are prefixed with `/mrp/v1/`.
|
|
32
|
+
|
|
33
|
+
| Endpoint | Method | Purpose |
|
|
34
|
+
|----------|--------|---------|
|
|
35
|
+
| `/capabilities` | GET | Runtime capabilities |
|
|
36
|
+
| `/sessions` | GET/POST | List/create sessions |
|
|
37
|
+
| `/execute` | POST | Run code |
|
|
38
|
+
| `/execute/stream` | POST | Run code with SSE streaming |
|
|
39
|
+
| `/complete` | POST | Get completions |
|
|
40
|
+
| `/inspect` | POST | Get symbol info |
|
|
41
|
+
| `/hover` | POST | Get hover tooltip |
|
|
42
|
+
| `/variables` | POST | List variables |
|
|
43
|
+
| `/interrupt` | POST | Cancel execution |
|
|
44
|
+
|
|
45
|
+
## Protocol
|
|
46
|
+
|
|
47
|
+
See [PROTOCOL.md](../mrmd-editor/PROTOCOL.md) for the full MRP specification.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mrmd-python"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Python runtime server implementing the MRMD Runtime Protocol (MRP)"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = { text = "MIT" }
|
|
8
|
+
authors = [{ name = "mrmd contributors" }]
|
|
9
|
+
keywords = ["notebook", "ipython", "runtime", "mrmd", "mrp"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 3 - Alpha",
|
|
12
|
+
"Intended Audience :: Developers",
|
|
13
|
+
"License :: OSI Approved :: MIT License",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3.10",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
dependencies = [
|
|
22
|
+
"starlette>=0.40.0",
|
|
23
|
+
"uvicorn>=0.32.0",
|
|
24
|
+
"sse-starlette>=2.0.0",
|
|
25
|
+
"ipython>=8.0.0",
|
|
26
|
+
"jedi>=0.19.0",
|
|
27
|
+
"black>=25.12.0",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
format = ["black>=24.0.0"]
|
|
32
|
+
dev = [
|
|
33
|
+
"pytest>=8.0.0",
|
|
34
|
+
"pytest-asyncio>=0.24.0",
|
|
35
|
+
"httpx>=0.27.0",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
mrmd-python = "mrmd_python.cli:main"
|
|
40
|
+
|
|
41
|
+
[build-system]
|
|
42
|
+
requires = ["hatchling"]
|
|
43
|
+
build-backend = "hatchling.build"
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.wheel]
|
|
46
|
+
packages = ["src/mrmd_python"]
|
|
47
|
+
|
|
48
|
+
[tool.pytest.ini_options]
|
|
49
|
+
asyncio_mode = "auto"
|
|
50
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""
|
|
2
|
+
mrmd-python: Python runtime server implementing the MRMD Runtime Protocol (MRP)
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
mrmd-python [--host HOST] [--port PORT] [--cwd DIR]
|
|
6
|
+
|
|
7
|
+
Or programmatically:
|
|
8
|
+
from mrmd_python import create_app
|
|
9
|
+
app = create_app()
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from .server import create_app, MRPServer
|
|
13
|
+
from .worker import IPythonWorker
|
|
14
|
+
|
|
15
|
+
__version__ = "0.1.0"
|
|
16
|
+
__all__ = ["create_app", "MRPServer", "IPythonWorker", "__version__"]
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""
|
|
2
|
+
mrmd-python CLI
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
mrmd-python [--host HOST] [--port PORT] [--cwd DIR] [--assets-dir DIR]
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import os
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
parser = argparse.ArgumentParser(
|
|
14
|
+
description="Python runtime server implementing the MRMD Runtime Protocol (MRP)"
|
|
15
|
+
)
|
|
16
|
+
parser.add_argument(
|
|
17
|
+
"--host",
|
|
18
|
+
default="localhost",
|
|
19
|
+
help="Host to bind to (default: localhost)",
|
|
20
|
+
)
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"--port",
|
|
23
|
+
type=int,
|
|
24
|
+
default=8000,
|
|
25
|
+
help="Port to bind to (default: 8000)",
|
|
26
|
+
)
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
"--cwd",
|
|
29
|
+
default=None,
|
|
30
|
+
help="Working directory (default: current directory)",
|
|
31
|
+
)
|
|
32
|
+
parser.add_argument(
|
|
33
|
+
"--assets-dir",
|
|
34
|
+
default=None,
|
|
35
|
+
help="Directory for saving assets (default: .mrmd-assets in cwd)",
|
|
36
|
+
)
|
|
37
|
+
parser.add_argument(
|
|
38
|
+
"--reload",
|
|
39
|
+
action="store_true",
|
|
40
|
+
help="Enable auto-reload for development",
|
|
41
|
+
)
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
"--venv",
|
|
44
|
+
default=None,
|
|
45
|
+
help="Path to virtual environment to use for code execution",
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
args = parser.parse_args()
|
|
49
|
+
|
|
50
|
+
# Import here to avoid slow startup for --help
|
|
51
|
+
import uvicorn
|
|
52
|
+
from .server import create_app
|
|
53
|
+
|
|
54
|
+
cwd = args.cwd or os.getcwd()
|
|
55
|
+
assets_dir = args.assets_dir or os.path.join(cwd, ".mrmd-assets")
|
|
56
|
+
venv = args.venv
|
|
57
|
+
|
|
58
|
+
venv_display = venv[:43] if venv else "System Python"
|
|
59
|
+
print(
|
|
60
|
+
f"""
|
|
61
|
+
╔═══════════════════════════════════════════════════════════════╗
|
|
62
|
+
║ mrmd-python MRP Server ║
|
|
63
|
+
╠═══════════════════════════════════════════════════════════════╣
|
|
64
|
+
║ Running on: http://{args.host}:{args.port}/mrp/v1{' ' * (26 - len(args.host) - len(str(args.port)))}║
|
|
65
|
+
║ ║
|
|
66
|
+
║ Endpoints: ║
|
|
67
|
+
║ GET /mrp/v1/capabilities ║
|
|
68
|
+
║ GET /mrp/v1/sessions ║
|
|
69
|
+
║ POST /mrp/v1/execute ║
|
|
70
|
+
║ POST /mrp/v1/execute/stream ║
|
|
71
|
+
║ POST /mrp/v1/complete ║
|
|
72
|
+
║ POST /mrp/v1/inspect ║
|
|
73
|
+
║ POST /mrp/v1/hover ║
|
|
74
|
+
║ POST /mrp/v1/variables ║
|
|
75
|
+
║ ║
|
|
76
|
+
║ Working directory: {cwd[:43]:<43}║
|
|
77
|
+
║ Assets directory: {assets_dir[:43]:<43}║
|
|
78
|
+
║ Virtual env: {venv_display:<43}║
|
|
79
|
+
║ ║
|
|
80
|
+
║ Press Ctrl+C to stop ║
|
|
81
|
+
╚═══════════════════════════════════════════════════════════════╝
|
|
82
|
+
"""
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Create app factory for uvicorn
|
|
86
|
+
def app_factory():
|
|
87
|
+
return create_app(cwd=cwd, assets_dir=assets_dir, venv=venv)
|
|
88
|
+
|
|
89
|
+
if args.reload:
|
|
90
|
+
global _cwd, _assets_dir, _venv
|
|
91
|
+
_cwd = cwd
|
|
92
|
+
_assets_dir = assets_dir
|
|
93
|
+
_venv = venv
|
|
94
|
+
uvicorn.run(
|
|
95
|
+
"mrmd_python.cli:_create_app_for_reload",
|
|
96
|
+
host=args.host,
|
|
97
|
+
port=args.port,
|
|
98
|
+
reload=True,
|
|
99
|
+
access_log=False, # Disable access log to prevent it leaking into execution output
|
|
100
|
+
)
|
|
101
|
+
else:
|
|
102
|
+
app = create_app(cwd=cwd, assets_dir=assets_dir, venv=venv)
|
|
103
|
+
uvicorn.run(app, host=args.host, port=args.port, access_log=False)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
# For reload mode
|
|
107
|
+
_cwd = None
|
|
108
|
+
_assets_dir = None
|
|
109
|
+
_venv = None
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _create_app_for_reload():
|
|
113
|
+
from .server import create_app
|
|
114
|
+
|
|
115
|
+
return create_app(cwd=_cwd, assets_dir=_assets_dir, venv=_venv)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if __name__ == "__main__":
|
|
119
|
+
main()
|