tortoise-orm-studio 1.0.0__py3-none-any.whl

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 (68) hide show
  1. tortoise_orm_studio/__init__.py +11 -0
  2. tortoise_orm_studio/adapters/__init__.py +1 -0
  3. tortoise_orm_studio/adapters/aiohttp_adapter.py +31 -0
  4. tortoise_orm_studio/adapters/asgi.py +89 -0
  5. tortoise_orm_studio/adapters/base.py +25 -0
  6. tortoise_orm_studio/adapters/django_adapter.py +84 -0
  7. tortoise_orm_studio/adapters/quart_adapter.py +32 -0
  8. tortoise_orm_studio/adapters/registry.py +39 -0
  9. tortoise_orm_studio/adapters/sanic_adapter.py +39 -0
  10. tortoise_orm_studio/auth.py +34 -0
  11. tortoise_orm_studio/cli.py +41 -0
  12. tortoise_orm_studio/core/__init__.py +1 -0
  13. tortoise_orm_studio/core/aerich.py +86 -0
  14. tortoise_orm_studio/core/ai.py +87 -0
  15. tortoise_orm_studio/core/audit.py +69 -0
  16. tortoise_orm_studio/core/config.py +58 -0
  17. tortoise_orm_studio/core/filters.py +94 -0
  18. tortoise_orm_studio/core/handler.py +249 -0
  19. tortoise_orm_studio/core/http.py +55 -0
  20. tortoise_orm_studio/core/i18n.py +18 -0
  21. tortoise_orm_studio/core/introspect.py +197 -0
  22. tortoise_orm_studio/core/manifest.py +128 -0
  23. tortoise_orm_studio/core/pagination.py +59 -0
  24. tortoise_orm_studio/core/permissions.py +46 -0
  25. tortoise_orm_studio/core/plugins.py +214 -0
  26. tortoise_orm_studio/core/ratelimit.py +32 -0
  27. tortoise_orm_studio/core/scoping.py +23 -0
  28. tortoise_orm_studio/core/serializers.py +61 -0
  29. tortoise_orm_studio/core/service.py +594 -0
  30. tortoise_orm_studio/plugins.py +8 -0
  31. tortoise_orm_studio/static/ALPINE_LICENSE.txt +11 -0
  32. tortoise_orm_studio/static/_types.d.ts +706 -0
  33. tortoise_orm_studio/static/a11y.js +115 -0
  34. tortoise_orm_studio/static/ai.js +66 -0
  35. tortoise_orm_studio/static/alpine.min.js +23 -0
  36. tortoise_orm_studio/static/app.css +514 -0
  37. tortoise_orm_studio/static/app.js +1443 -0
  38. tortoise_orm_studio/static/audit.js +171 -0
  39. tortoise_orm_studio/static/copy-as.js +118 -0
  40. tortoise_orm_studio/static/er-layout.js +227 -0
  41. tortoise_orm_studio/static/er.js +296 -0
  42. tortoise_orm_studio/static/filters.js +114 -0
  43. tortoise_orm_studio/static/i18n.en.js +190 -0
  44. tortoise_orm_studio/static/i18n.js +140 -0
  45. tortoise_orm_studio/static/i18n.zh-CN.js +189 -0
  46. tortoise_orm_studio/static/index.html +515 -0
  47. tortoise_orm_studio/static/inline-edit.js +107 -0
  48. tortoise_orm_studio/static/json-view.js +161 -0
  49. tortoise_orm_studio/static/migrations.js +139 -0
  50. tortoise_orm_studio/static/palette.js +141 -0
  51. tortoise_orm_studio/static/pending.js +240 -0
  52. tortoise_orm_studio/static/pickers.js +230 -0
  53. tortoise_orm_studio/static/playground.js +105 -0
  54. tortoise_orm_studio/static/query-history.js +84 -0
  55. tortoise_orm_studio/static/shortcuts.js +145 -0
  56. tortoise_orm_studio/static/state-hash.js +112 -0
  57. tortoise_orm_studio/static/tabs.js +368 -0
  58. tortoise_orm_studio/static/theme-init.js +33 -0
  59. tortoise_orm_studio/static/theme.js +106 -0
  60. tortoise_orm_studio/static/toasts.js +76 -0
  61. tortoise_orm_studio/static/views.js +70 -0
  62. tortoise_orm_studio/static/widgets.js +345 -0
  63. tortoise_orm_studio/studio.py +51 -0
  64. tortoise_orm_studio-1.0.0.dist-info/METADATA +177 -0
  65. tortoise_orm_studio-1.0.0.dist-info/RECORD +68 -0
  66. tortoise_orm_studio-1.0.0.dist-info/WHEEL +4 -0
  67. tortoise_orm_studio-1.0.0.dist-info/entry_points.txt +2 -0
  68. tortoise_orm_studio-1.0.0.dist-info/licenses/LICENSE +13 -0
@@ -0,0 +1,345 @@
1
+ // @ts-check
2
+ /**
3
+ * Typed form widgets for tortoise-orm-studio.
4
+ *
5
+ * Loaded as a classic script before app.js. Exposes ``window.StudioWidgets``.
6
+ * No eval, no inline handlers, no HTML assignment — safe under the same
7
+ * strict CSP the rest of the UI runs under.
8
+ *
9
+ * Types (Field, FieldKind, WidgetsAPI) come from _types.d.ts.
10
+ */
11
+
12
+ (function (/** @type {Window & { StudioWidgets?: WidgetsAPI }} */ global) {
13
+ "use strict";
14
+
15
+ /**
16
+ * @template {keyof HTMLElementTagNameMap} K
17
+ * @param {K} tag
18
+ * @param {Record<string, any>} props
19
+ * @param {Array<Node|string>} [children]
20
+ * @returns {HTMLElementTagNameMap[K]}
21
+ */
22
+ function create(tag, props, children) {
23
+ /** @type {any} */
24
+ const el = document.createElement(tag);
25
+ for (const k of Object.keys(props || {})) {
26
+ const v = props[k];
27
+ if (v === undefined) continue;
28
+ if (k === "class") el.className = v;
29
+ else if (k.startsWith("on") && typeof v === "function") el.addEventListener(k.slice(2), v);
30
+ else if (k in el) el[k] = v;
31
+ else el.setAttribute(k, String(v));
32
+ }
33
+ for (const c of children || []) {
34
+ el.appendChild(typeof c === "string" ? document.createTextNode(c) : c);
35
+ }
36
+ return el;
37
+ }
38
+
39
+ /**
40
+ * @param {HTMLElement|null} errEl
41
+ * @param {string|null} message
42
+ */
43
+ function setError(errEl, message) {
44
+ if (errEl) errEl.textContent = message || "";
45
+ }
46
+
47
+ /**
48
+ * @param {Field} field
49
+ * @param {unknown} value
50
+ * @returns {string|null}
51
+ */
52
+ function validate(field, value) {
53
+ if (value === null || value === undefined) {
54
+ return field.null || field.pk ? null : "Required";
55
+ }
56
+ switch (field.kind) {
57
+ case "int":
58
+ return Number.isInteger(value) ? null : "Must be an integer";
59
+ case "float":
60
+ return typeof value === "number" && Number.isFinite(value) ? null : "Must be a number";
61
+ case "decimal":
62
+ return /^-?\d+(\.\d+)?$/.test(String(value)) ? null : "Must be a decimal";
63
+ case "uuid":
64
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(String(value))
65
+ ? null : "Must be a UUID";
66
+ case "enum":
67
+ return Array.isArray(field.choices) && field.choices.indexOf(String(value)) === -1
68
+ ? "Not a valid choice" : null;
69
+ case "json":
70
+ try { JSON.stringify(value); return null; } catch { return "Invalid JSON"; }
71
+ case "date":
72
+ return /^\d{4}-\d{2}-\d{2}$/.test(String(value)) ? null : "Must be YYYY-MM-DD";
73
+ case "time":
74
+ return /^\d{2}:\d{2}(:\d{2})?$/.test(String(value)) ? null : "Must be HH:MM[:SS]";
75
+ case "datetime":
76
+ return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?$/.test(String(value))
77
+ ? null : "Must be YYYY-MM-DDTHH:MM[:SS]";
78
+ case "fk":
79
+ case "o2o":
80
+ return null; // validity is checked server-side
81
+ default:
82
+ return null;
83
+ }
84
+ }
85
+
86
+ /** @param {unknown} v */
87
+ function normalizeDate(v) {
88
+ if (v === null || v === undefined || v === "") return "";
89
+ return String(v).slice(0, 10);
90
+ }
91
+
92
+ /** @param {unknown} v */
93
+ function normalizeTime(v) {
94
+ if (v === null || v === undefined || v === "") return "";
95
+ return String(v).slice(0, 8);
96
+ }
97
+
98
+ /** @param {unknown} v */
99
+ function normalizeDatetime(v) {
100
+ if (v === null || v === undefined || v === "") return "";
101
+ return String(v).replace(/Z$/, "").replace(/[+-]\d{2}:?\d{2}$/, "").slice(0, 19);
102
+ }
103
+
104
+ /** @param {string} v */
105
+ function toIso(v) {
106
+ return v.length === 16 ? v + ":00" : v;
107
+ }
108
+
109
+ /**
110
+ * @param {Field} field
111
+ * @param {unknown} value
112
+ * @param {(name: string, value: unknown) => void} onChange
113
+ * @param {HTMLElement|null} errEl
114
+ * @returns {HTMLElement}
115
+ */
116
+ function buildInput(field, value, onChange, errEl) {
117
+ const id = "f_" + field.name;
118
+
119
+ /** @param {unknown} next */
120
+ function fire(next) {
121
+ const err = validate(field, next);
122
+ setError(errEl, err);
123
+ if (!err) onChange(field.name, next);
124
+ }
125
+
126
+ switch (field.kind) {
127
+ case "bool":
128
+ return create("input", {
129
+ type: "checkbox", id: id,
130
+ checked: !!value, disabled: field.readonly,
131
+ onchange: function (/** @type {Event} */ e) {
132
+ // @ts-ignore
133
+ fire(e.target.checked);
134
+ },
135
+ });
136
+
137
+ case "int":
138
+ return create("input", {
139
+ type: "number", id: id, step: "1",
140
+ value: value === null || value === undefined ? "" : String(value),
141
+ disabled: field.readonly,
142
+ oninput: function (/** @type {Event} */ e) {
143
+ // @ts-ignore
144
+ const s = e.target.value;
145
+ if (s === "") return fire(field.null ? null : 0);
146
+ const n = parseInt(s, 10);
147
+ fire(Number.isNaN(n) ? null : n);
148
+ },
149
+ });
150
+
151
+ case "float":
152
+ case "decimal":
153
+ return create("input", {
154
+ type: "number", id: id,
155
+ step: field.kind === "float" ? "any" : "0.01",
156
+ value: value === null || value === undefined ? "" : String(value),
157
+ disabled: field.readonly,
158
+ oninput: function (/** @type {Event} */ e) {
159
+ // @ts-ignore
160
+ const s = e.target.value;
161
+ if (s === "") return fire(field.null ? null : 0);
162
+ fire(field.kind === "decimal" ? s : parseFloat(s));
163
+ },
164
+ });
165
+
166
+ case "string":
167
+ case "uuid": {
168
+ /** @type {Record<string, any>} */
169
+ const props = {
170
+ type: "text", id: id,
171
+ value: value === null || value === undefined ? "" : String(value),
172
+ disabled: field.readonly,
173
+ oninput: function (/** @type {Event} */ e) {
174
+ // @ts-ignore
175
+ const s = e.target.value;
176
+ fire(s === "" && field.null ? null : s);
177
+ },
178
+ };
179
+ if (field.max_length) props.maxLength = field.max_length;
180
+ return create("input", props);
181
+ }
182
+
183
+ case "text":
184
+ return create("textarea", {
185
+ id: id, rows: 4,
186
+ value: value === null || value === undefined ? "" : String(value),
187
+ disabled: field.readonly,
188
+ oninput: function (/** @type {Event} */ e) {
189
+ // @ts-ignore
190
+ const s = e.target.value;
191
+ fire(s === "" && field.null ? null : s);
192
+ },
193
+ });
194
+
195
+ case "enum": {
196
+ /** @type {HTMLElement[]} */
197
+ const opts = [create("option", { value: "" }, [field.null ? "(null)" : ""])];
198
+ const choices = field.choices || [];
199
+ for (let i = 0; i < choices.length; i++) {
200
+ const c = choices[i];
201
+ opts.push(create("option", { value: c, selected: c === value }, [c]));
202
+ }
203
+ return create("select", {
204
+ id: id, disabled: field.readonly,
205
+ onchange: function (/** @type {Event} */ e) {
206
+ // @ts-ignore
207
+ const s = e.target.value;
208
+ fire(s === "" && field.null ? null : s);
209
+ },
210
+ }, opts);
211
+ }
212
+
213
+ case "date":
214
+ return create("input", {
215
+ type: "date", id: id,
216
+ value: normalizeDate(value), disabled: field.readonly,
217
+ oninput: function (/** @type {Event} */ e) {
218
+ // @ts-ignore
219
+ fire(e.target.value || null);
220
+ },
221
+ });
222
+
223
+ case "time":
224
+ return create("input", {
225
+ type: "time", id: id, step: "1",
226
+ value: normalizeTime(value), disabled: field.readonly,
227
+ oninput: function (/** @type {Event} */ e) {
228
+ // @ts-ignore
229
+ fire(e.target.value || null);
230
+ },
231
+ });
232
+
233
+ case "datetime":
234
+ return create("input", {
235
+ type: "datetime-local", id: id, step: "1",
236
+ value: normalizeDatetime(value), disabled: field.readonly,
237
+ oninput: function (/** @type {Event} */ e) {
238
+ // @ts-ignore
239
+ const s = e.target.value;
240
+ fire(s ? toIso(s) : null);
241
+ },
242
+ });
243
+
244
+ case "json":
245
+ return create("textarea", {
246
+ id: id, rows: 6, class: "json-input",
247
+ value: value === null || value === undefined ? "" : JSON.stringify(value, null, 2),
248
+ disabled: field.readonly,
249
+ oninput: function (/** @type {Event} */ e) {
250
+ // @ts-ignore
251
+ const s = e.target.value;
252
+ if (s.trim() === "") return fire(field.null ? null : {});
253
+ try { fire(JSON.parse(s)); }
254
+ catch { setError(errEl, "Invalid JSON"); }
255
+ },
256
+ });
257
+
258
+ case "binary": {
259
+ const raw = /** @type {any} */ (value);
260
+ return create("input", {
261
+ type: "text", id: id, placeholder: "base64",
262
+ value: raw && raw.__binary__ ? String(raw.__binary__) : "",
263
+ disabled: field.readonly,
264
+ oninput: function (/** @type {Event} */ e) {
265
+ // @ts-ignore
266
+ const s = e.target.value.trim();
267
+ fire(s === "" ? null : { __binary__: s });
268
+ },
269
+ });
270
+ }
271
+
272
+ case "fk":
273
+ case "o2o": {
274
+ const wrap = create("div", { class: "fk-widget" });
275
+ const dv = field.display_value != null
276
+ ? String(field.display_value)
277
+ : (value === null || value === undefined ? "(none)" : String(value));
278
+ const display = create("input", {
279
+ type: "text", id: id, readonly: true, class: "fk-display",
280
+ value: dv,
281
+ });
282
+ const pick = create("button", {
283
+ type: "button", class: "fk-pick", disabled: field.readonly,
284
+ }, ["Pick"]);
285
+ const clear = create("button", {
286
+ type: "button", class: "fk-clear",
287
+ disabled: field.readonly || value === null || value === undefined,
288
+ }, ["Clear"]);
289
+ pick.addEventListener("click", function () {
290
+ const P = /** @type {any} */ (/** @type {any} */ (window).StudioPicker);
291
+ if (!P) { setError(errEl, "pickers.js not loaded"); return; }
292
+ P.request({
293
+ model: field.related_model || "",
294
+ label: field.name,
295
+ onSelect: function (/** @type {unknown} */ pk) {
296
+ fire(pk);
297
+ display.value = String(pk);
298
+ clear.disabled = false;
299
+ },
300
+ onCancel: function () { /* no-op */ },
301
+ });
302
+ });
303
+ clear.addEventListener("click", function () {
304
+ fire(null);
305
+ display.value = "(none)";
306
+ clear.disabled = true;
307
+ });
308
+ wrap.appendChild(display);
309
+ wrap.appendChild(pick);
310
+ wrap.appendChild(clear);
311
+ return wrap;
312
+ }
313
+
314
+ default:
315
+ return create("input", {
316
+ type: "text", id: id,
317
+ value: value === null || value === undefined ? "" : String(value),
318
+ disabled: field.readonly,
319
+ oninput: function (/** @type {Event} */ e) {
320
+ // @ts-ignore
321
+ fire(e.target.value);
322
+ },
323
+ });
324
+ }
325
+ }
326
+
327
+ /**
328
+ * @param {Field} field
329
+ * @param {unknown} value
330
+ * @param {(name: string, value: unknown) => void} onChange
331
+ * @returns {HTMLElement}
332
+ */
333
+ function renderField(field, value, onChange) {
334
+ const label = create("label", { htmlFor: "f_" + field.name, class: "widget-label" }, [
335
+ field.name + (field.null ? " (nullable)" : ""),
336
+ ]);
337
+ const err = create("span", { class: "widget-error", id: "f_" + field.name + "_err" });
338
+ const input = buildInput(field, value, onChange, err);
339
+ return create("div", { class: "widget" + (field.readonly ? " readonly" : "") }, [
340
+ label, input, err,
341
+ ]);
342
+ }
343
+
344
+ global.StudioWidgets = { renderField: renderField, validate: validate };
345
+ })(window);
@@ -0,0 +1,51 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Iterable, Optional, Set
4
+
5
+ from .core.config import AuditHook, AuthHook, ModelConfig, StudioConfig
6
+ from .core.handler import StudioHandler
7
+ from .core.http import StudioRequest, StudioResponse
8
+ from .core.i18n import LOCALES, normalize_locale
9
+ from .core.plugins import EMPTY, PluginManager, StudioPlugin
10
+ from .core.service import StudioService
11
+
12
+
13
+ class Studio:
14
+ def __init__(self, read_only: bool = True, auth: Optional[AuthHook] = None, allow_remote: bool = False,
15
+ allow_models: Optional[Set[str]] = None, deny_models: Optional[Set[str]] = None,
16
+ audit: Optional[AuditHook] = None, permissions: Any = None,
17
+ scope: Any = None, rate_limiter: Any = None,
18
+ cursor_secret: str = "tortoise-orm-studio", ai_filter: Any = None,
19
+ ai_timeout: float = 10.0, ai_max_prompt: int = 2000,
20
+ plugins: Optional[Iterable[StudioPlugin]] = None,
21
+ locale: str = "en", **limits: Any):
22
+ self.config = StudioConfig(read_only=read_only, auth=auth, allow_remote=allow_remote,
23
+ allow_models=allow_models, deny_models=deny_models or set(),
24
+ audit=audit, permissions=permissions,
25
+ scope=scope, rate_limiter=rate_limiter,
26
+ cursor_secret=cursor_secret, ai_filter=ai_filter,
27
+ ai_timeout=ai_timeout, ai_max_prompt=ai_max_prompt,
28
+ plugins=tuple(plugins or ()),
29
+ locale=normalize_locale(locale), locales=LOCALES, **limits)
30
+ self.plugin_manager = PluginManager(self.config.plugins) if plugins else EMPTY
31
+ self.plugin_manager.configure(self)
32
+ self.service = StudioService(self.config)
33
+ self.handler = StudioHandler(self.service, self.config, self.plugin_manager)
34
+
35
+ def register(self, model: type, **options: Any) -> Studio:
36
+ """Per-model tweaks: list_display, search_fields, readonly_fields, exclude."""
37
+ self.config.model_cfg[model] = ModelConfig(**options)
38
+ return self
39
+
40
+ async def handle(self, req: StudioRequest) -> StudioResponse:
41
+ """The single entry point every adapter calls."""
42
+ return await self.handler.handle(req)
43
+
44
+ def asgi(self, tortoise_config: Optional[dict] = None):
45
+ from .adapters.asgi import StudioASGI
46
+ return StudioASGI(self, tortoise_config)
47
+
48
+ def mount(self, app: Any, framework: str, **kwargs: Any) -> None:
49
+ """studio.mount(app, "aiohttp", prefix="/studio") - looks up a built-in or plugin adapter."""
50
+ from .adapters.registry import get_installer
51
+ get_installer(framework)(app, self, **kwargs)
@@ -0,0 +1,177 @@
1
+ Metadata-Version: 2.4
2
+ Name: tortoise-orm-studio
3
+ Version: 1.0.0
4
+ Summary: A browser-based data viewer/editor for Tortoise ORM, with adapters for any framework.
5
+ Project-URL: Homepage, https://github.com/aldanedev-create/tortoise-orm-studio
6
+ Project-URL: Source, https://github.com/aldanedev-create/tortoise-orm-studio
7
+ Project-URL: Issues, https://github.com/aldanedev-create/tortoise-orm-studio/issues
8
+ Project-URL: Changelog, https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/CHANGELOG.md
9
+ Author-email: Aldane <aldanehutchinson5@gmail.com>
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: admin,aiohttp,database,fastapi,litestar,orm,prisma-studio,quart,sanic,starlette,studio,tortoise-orm
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Framework :: AsyncIO
15
+ Classifier: Framework :: FastAPI
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Topic :: Database
26
+ Classifier: Topic :: Software Development :: User Interfaces
27
+ Requires-Python: >=3.9
28
+ Requires-Dist: tortoise-orm<2.0,>=0.21
29
+ Provides-Extra: aiohttp
30
+ Requires-Dist: aiohttp>=3.9; extra == 'aiohttp'
31
+ Provides-Extra: cli
32
+ Requires-Dist: uvicorn>=0.23; extra == 'cli'
33
+ Provides-Extra: dev
34
+ Requires-Dist: aiosqlite; extra == 'dev'
35
+ Requires-Dist: build; extra == 'dev'
36
+ Requires-Dist: httpx; extra == 'dev'
37
+ Requires-Dist: mypy; extra == 'dev'
38
+ Requires-Dist: pytest; extra == 'dev'
39
+ Requires-Dist: pytest-asyncio; extra == 'dev'
40
+ Requires-Dist: pytest-cov; extra == 'dev'
41
+ Requires-Dist: ruff; extra == 'dev'
42
+ Provides-Extra: django
43
+ Requires-Dist: django>=4.1; extra == 'django'
44
+ Provides-Extra: fastapi
45
+ Requires-Dist: fastapi>=0.100; extra == 'fastapi'
46
+ Provides-Extra: litestar
47
+ Requires-Dist: litestar>=2.0; extra == 'litestar'
48
+ Provides-Extra: quart
49
+ Requires-Dist: quart>=0.19; extra == 'quart'
50
+ Provides-Extra: sanic
51
+ Requires-Dist: sanic>=23.3; extra == 'sanic'
52
+ Provides-Extra: starlette
53
+ Requires-Dist: starlette>=0.30; extra == 'starlette'
54
+ Description-Content-Type: text/markdown
55
+
56
+ # tortoise-orm-studio
57
+
58
+ <div align="center">
59
+ <a href="https://aldanedev-create.github.io/tortoise-orm-studio/#/">
60
+ <img src="https://raw.githubusercontent.com/aldanedev-create/tortoise-orm-studio/main/assets/favicon.svg" alt=" tortoise-orm-studio logo" width="200">
61
+ </a>
62
+ </div>
63
+
64
+ A browser-based data viewer and editor for [Tortoise ORM](https://tortoise.github.io/) (think Prisma Studio). Unofficial; not affiliated with Tortoise ORM or Prisma.
65
+ ⬇️⬇️
66
+ [Doc Website](https://aldanedev-create.github.io/tortoise-orm-studio/#/)
67
+
68
+ [![PyPI](https://img.shields.io/pypi/v/tortoise-orm-studio.svg)](https://pypi.org/project/tortoise-orm-studio/)
69
+ [![Python](https://img.shields.io/pypi/pyversions/tortoise-orm-studio.svg)](https://pypi.org/project/tortoise-orm-studio/)
70
+ [![CI](https://github.com/aldanedev-create/tortoise-orm-studio/actions/workflows/ci.yml/badge.svg)](https://github.com/aldanedev-create/tortoise-orm-studio/actions/workflows/ci.yml)
71
+ [![Docs](https://github.com/aldanedev-create/tortoise-orm-studio/actions/workflows/docs.yml/badge.svg)](https://aldanedev-create.github.io/tortoise-orm-studio/)
72
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/LICENSE)
73
+
74
+ ![tortoise-orm-studio demo: search, detail drawer, switching models, ER diagram, query playground and dark mode](https://raw.githubusercontent.com/aldanedev-create/tortoise-orm-studio/main/docs/assets/demo.gif)
75
+
76
+ ## Install from PyPI
77
+
78
+ ```bash
79
+ pip install tortoise-orm-studio
80
+ ```
81
+
82
+ Add an extra for your framework, or `cli` for the standalone server:
83
+
84
+ ```bash
85
+ pip install "tortoise-orm-studio[cli]" # standalone server (uvicorn)
86
+ pip install "tortoise-orm-studio[fastapi]" # or: starlette, litestar, aiohttp, sanic, quart, django
87
+ ```
88
+
89
+ Requires Python 3.9+ and Tortoise ORM 0.21 to 1.x.
90
+
91
+ ### Run it against your own models
92
+
93
+ With the `cli` extra installed, point Studio at your `TORTOISE_ORM` config dict:
94
+
95
+ ```bash
96
+ tortoise-orm-studio --config settings.TORTOISE_ORM
97
+ # http://127.0.0.1:5555 (read-only by default)
98
+ ```
99
+
100
+ Add `--write` to enable create, edit and delete. Binding to a non-local host requires `--password`. See the [CLI reference](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/reference/cli.md).
101
+
102
+ ## Clone and try the demo
103
+
104
+ Want to see it with sample data first? Clone the repo and run the dev server:
105
+
106
+ ```bash
107
+ git clone https://github.com/aldanedev-create/tortoise-orm-studio.git
108
+ cd tortoise-orm-studio
109
+ pip install -e ".[fastapi,cli]" aiosqlite
110
+ python examples/dev_server.py --fresh
111
+ # http://127.0.0.1:8000/studio/ login: admin / change-me
112
+ ```
113
+
114
+ The dev server uses the sample models from `tests/models.py`. See the [quickstart](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/getting-started/quickstart.md) for the full walkthrough.
115
+
116
+ ## Mount in your app
117
+
118
+ ```python
119
+ from fastapi import FastAPI
120
+ from tortoise_orm_studio import Studio, basic_auth
121
+
122
+ app = FastAPI()
123
+ studio = Studio(read_only=False, auth=basic_auth("admin", "change-me"))
124
+ studio.mount(app, "fastapi", prefix="/studio")
125
+ ```
126
+
127
+ > **Local development only.** The `basic_auth("admin", "change-me")` credentials above are a placeholder for a local demo — **never deploy this as-is**. Use real credentials (or your own auth hook), start with `read_only=True`, terminate HTTPS at a proxy, and set a unique `cursor_secret`. To reach a localhost-only Studio remotely, use an SSH tunnel rather than exposing the port. See the [Production checklist](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/guides/production.md).
128
+
129
+ | Framework | Call |
130
+ |---|---|
131
+ | FastAPI / Starlette | `studio.mount(app, "fastapi"/"starlette", prefix="/studio")` |
132
+ | Litestar | `studio.mount(app, "litestar", prefix="/studio")` |
133
+ | aiohttp | `studio.mount(app, "aiohttp", prefix="/studio")` |
134
+ | Sanic | `studio.mount(app, "sanic", prefix="/studio")` |
135
+ | Quart | `studio.mount(app, "quart", prefix="/studio")` |
136
+ | Django | `urlpatterns = [*urls(studio, prefix="studio")]` — `mount()` raises `NotImplementedError`; Django 4.1+ on ASGI |
137
+ | Standalone ASGI | `app = studio.asgi(tortoise_config=TORTOISE_ORM)` |
138
+
139
+ See [Framework mounting](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/guides/frameworks.md) and [Wrapping Studio for other frameworks](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/guides/other-frameworks.md).
140
+
141
+ ## Safe defaults
142
+
143
+ Read-only, localhost-only, CSRF header on writes, whitelisted filters, CSV-injection guard. No telemetry, no bundled AI model or key, no external fonts or trackers. **Never expose Studio without auth.**
144
+
145
+ Behind a reverse proxy, requests carrying `x-forwarded-for` or `forwarded` are refused with **403 `forbidden`** unless `auth=` is set — configure auth rather than treating this as a bug. See the [Security model](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/reference/security.md).
146
+
147
+ ## Screenshots
148
+
149
+ | List | Detail drawer | ER diagram |
150
+ |---|---|---|
151
+ | ![List](https://raw.githubusercontent.com/aldanedev-create/tortoise-orm-studio/main/docs/assets/screenshots/list-light.png) | ![Drawer](https://raw.githubusercontent.com/aldanedev-create/tortoise-orm-studio/main/docs/assets/screenshots/drawer-light.png) | ![ER](https://raw.githubusercontent.com/aldanedev-create/tortoise-orm-studio/main/docs/assets/screenshots/er-light.png) |
152
+
153
+ | Playground | Audit log | Command palette |
154
+ |---|---|---|
155
+ | ![Playground](https://raw.githubusercontent.com/aldanedev-create/tortoise-orm-studio/main/docs/assets/screenshots/playground-light.png) | ![Audit](https://raw.githubusercontent.com/aldanedev-create/tortoise-orm-studio/main/docs/assets/screenshots/audit-light.png) | ![Palette](https://raw.githubusercontent.com/aldanedev-create/tortoise-orm-studio/main/docs/assets/screenshots/palette-light.png) |
156
+
157
+ ## Features
158
+
159
+ - **Browse & filter** — search, whitelisted filters, sort, columns, saved views, tabs with split, pinned models, shareable URL-hash state. [Using the UI](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/guides/using-the-ui.md) · [Filtering](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/guides/filtering-and-search.md)
160
+ - **Edit** — inline edit with undo, detail drawer, staged changes committed in one atomic transaction, Copy-as menu, JSON tree. [Editing data](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/guides/editing-data.md)
161
+ - **Inspect** — query playground with Python/SQL preview, in-app ER diagram, Aerich migrations, audit log. [Playground](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/guides/using-the-ui.md) · [Audit log](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/guides/audit-log.md)
162
+ - **Extend** — host plugins with namespaced routes and UI actions; optional AI filter hook. [Plugins](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/guides/plugins.md) · [AI filter hook](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/guides/ai-filter.md)
163
+ - **Operate** — authentication, permissions, row scope, localization (English/Chinese), WCAG A/AA accessibility, responsive layout, production checklist. [Authentication](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/guides/authentication.md) · [Production checklist](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/guides/production.md)
164
+ - **HTTP API** — every route under `/api/v1/`, with curl examples. [HTTP API](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/reference/http-api.md)
165
+
166
+ ## Using with AI agents
167
+
168
+ A copy-to-clipboard setup block that tells an agent how to install, mount, secure (read-only first, auth, unique `cursor_secret`) and verify Studio is in the [AI agents guide](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/guides/ai-agents.md). The docs site also offers "Copy page as Markdown" and `llms.txt` / `llms-full.txt` for AI tools. **Never expose Studio without auth.**
169
+
170
+ ## Links
171
+
172
+ - [Documentation](https://aldanedev-create.github.io/tortoise-orm-studio/) — also browsable as plain Markdown in [`docs/`](https://github.com/aldanedev-create/tortoise-orm-studio/tree/main/docs)
173
+ -[doc-site](https://aldanedev-create.github.io/tortoise-orm-studio/#/) doc website for tortoise-orm-studio
174
+ - [Changelog](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/CHANGELOG.md) · [Security model](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/reference/security.md) · [Stability policy](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/reference/stability.md)
175
+ - [Contributing](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/project/contributing.md) · [Troubleshooting](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/project/troubleshooting.md) · [FAQ](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/project/faq.md)
176
+
177
+ Public API is frozen as of 1.0.0; see [Stability policy](https://github.com/aldanedev-create/tortoise-orm-studio/blob/main/docs/reference/stability.md).
@@ -0,0 +1,68 @@
1
+ tortoise_orm_studio/__init__.py,sha256=yoNycBLOsQ06TITdZxuSo1z7TJd8Cdd_TTouBuOfyA4,399
2
+ tortoise_orm_studio/auth.py,sha256=_8TD4pFcsq1oD77Rz0v6r0BlgT-kpFsyDeuCj66Tu7Y,1094
3
+ tortoise_orm_studio/cli.py,sha256=t3NXREpB2FP5ZZZxuu1wfe-58XbY0xVXEZe9SB2zucs,1686
4
+ tortoise_orm_studio/plugins.py,sha256=EMDUfLLYtjG3FPOF5BcVnSTdnVnVbiAdqGfjYqcdR-A,360
5
+ tortoise_orm_studio/studio.py,sha256=LGk09FvNLAr85sC0DOROYdCbOORb8FL14pBj5Uym0Q8,2862
6
+ tortoise_orm_studio/adapters/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
7
+ tortoise_orm_studio/adapters/aiohttp_adapter.py,sha256=NgspK8TpYfqJVxRuJO3QL0qwM_9Qlcn_JR54ajA81gY,1198
8
+ tortoise_orm_studio/adapters/asgi.py,sha256=cb5tE4Gf-NxrpZqwM3qFv1hzUN1tByHli8523n3F9qg,4369
9
+ tortoise_orm_studio/adapters/base.py,sha256=rSnVQXdvDEsb7zQknh2Uhpwbev2V1ZNkJTqflPojbIo,1006
10
+ tortoise_orm_studio/adapters/django_adapter.py,sha256=QYoshulpr3Koqw1L81xf1B0Xusd-VRJycb42b_dW2p8,2902
11
+ tortoise_orm_studio/adapters/quart_adapter.py,sha256=pppyVDQ07nQCyIC2MhD7YhHZXP38BH0Ff-ATgXtZXIk,1250
12
+ tortoise_orm_studio/adapters/registry.py,sha256=vkO8WTIK4bTYgHoDaY9WhqQkYvYgM4-c8VP2H1DO5pU,1598
13
+ tortoise_orm_studio/adapters/sanic_adapter.py,sha256=tS0j0X05-VDRFAsd-JpRz90za3sfQ3IYMD9ScWjfO0s,1565
14
+ tortoise_orm_studio/core/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
15
+ tortoise_orm_studio/core/aerich.py,sha256=RHtc3RjTXBAgatzFfwwEuZPOSHI_GRuDIQoJrn3y2Jc,3073
16
+ tortoise_orm_studio/core/ai.py,sha256=F6rFtUoOpYuG8RaQIASzFhLuPDR3-enkBPtyqiTIzHQ,4003
17
+ tortoise_orm_studio/core/audit.py,sha256=5zCCOlB1Ckz8--vbhuYURGTq5MoprHdHcuFH-M7gjJ4,2384
18
+ tortoise_orm_studio/core/config.py,sha256=StZ1dmkqCvDnrrnSh4kg2xVSARvWun4gaaLioX5angs,2465
19
+ tortoise_orm_studio/core/filters.py,sha256=SNXYAddPjx5wcAPVIk4WX4hBzFJqAgWUpxQMCahTRms,3826
20
+ tortoise_orm_studio/core/handler.py,sha256=pozk5FTT5RyFPm94ZepyCeG741J1Yqr1VDqRq0lIitc,11801
21
+ tortoise_orm_studio/core/http.py,sha256=wRM0v4yv1rWxTQYBOYSxI_rNJOPjRcVysLDUGlBVFJo,2289
22
+ tortoise_orm_studio/core/i18n.py,sha256=Xm_tRvcpZ_KzSc7uTRzcWfSgsc87MdyYL8_T4jw_hWw,655
23
+ tortoise_orm_studio/core/introspect.py,sha256=yv3nPJLNTOQ1YwEr51dn0mshagqLwTVsLgHay4Ddm90,8103
24
+ tortoise_orm_studio/core/manifest.py,sha256=6gQCxYOe6o0y58bDUGcRBJjgL3WjzqOzkv1xxQtfYt8,5312
25
+ tortoise_orm_studio/core/pagination.py,sha256=pvDPnZ2yO8SkRm5RR6jgyCly7wZlbuMpJnonPRDl_lw,2243
26
+ tortoise_orm_studio/core/permissions.py,sha256=rF24-vWcP4Bs41HwI7L0kA2n0aPjRWj2XaMpXamxE8s,1802
27
+ tortoise_orm_studio/core/plugins.py,sha256=o47Lh9vpocDMH4ET5Q5mBAmxkSz0rw4kdeEGiUJsLIs,8708
28
+ tortoise_orm_studio/core/ratelimit.py,sha256=mpKBWHWfR4vAAKUbNMTTzPFOtfc3VoZwc__l6vkj0mw,1119
29
+ tortoise_orm_studio/core/scoping.py,sha256=Rsxoz6hKpl9xo-yG0Cn2S1StyLFc_Zh4aXKkH_oaifE,836
30
+ tortoise_orm_studio/core/serializers.py,sha256=9jFjGv9IWCe4LtUEmXhL8JX4pPAtSOr2NJ7yj8VLML0,1897
31
+ tortoise_orm_studio/core/service.py,sha256=FrdItsRAViefeWaUxjHXF2oHCq_hPZgsoOezrrUoeYY,29375
32
+ tortoise_orm_studio/static/ALPINE_LICENSE.txt,sha256=Np1ED_o_2aIaNnlqxRl2eTcErqZnaYnHzbGJg2J2z1o,771
33
+ tortoise_orm_studio/static/_types.d.ts,sha256=F_--6dtxvCwNkY2vUyxncN5RZpqzlBpK0Kjr4mk4mio,21978
34
+ tortoise_orm_studio/static/a11y.js,sha256=j8uYz5U65RZIVa0pe46aV9eVnGMXIvThXXha_DxN5DU,3955
35
+ tortoise_orm_studio/static/ai.js,sha256=e5qzjb7cMt_up4aSw63eG2CNKJno8CjoTjQGaVd3bXs,2099
36
+ tortoise_orm_studio/static/alpine.min.js,sha256=SMFwySAy5SfLrnG4znXPH5bKBvqGmmEg7w_kONjpLDY,72242
37
+ tortoise_orm_studio/static/app.css,sha256=OtOkcwj9vuymvSBvs6DZW5oLY7vSHY-614cf6LZ5pGQ,33873
38
+ tortoise_orm_studio/static/app.js,sha256=6thyQsQkhzEWYiolt1-IEfA4l-5yhCMawrkIvXPn3eg,58167
39
+ tortoise_orm_studio/static/audit.js,sha256=tXmDZmVhlpC4zrPqucAPWKl6gl1b1kEcJc7JUPWYKI8,5982
40
+ tortoise_orm_studio/static/copy-as.js,sha256=2JupGR1ThJb6fx2Bwse0tX6YeUX25qW2HCTvKiJ6AEk,3887
41
+ tortoise_orm_studio/static/er-layout.js,sha256=jdgae2_Pxnonf2PsTJ79D4jjK18zR9vejwsYXovL4oY,8608
42
+ tortoise_orm_studio/static/er.js,sha256=C5f-AbuRPM00riOVxszEbwFpuVe-CGizSKM8IAymCt8,11937
43
+ tortoise_orm_studio/static/filters.js,sha256=uzxXgZrsiZqhxxswRH9LrutziQlBuoqNdu-z2rvT4-s,3602
44
+ tortoise_orm_studio/static/i18n.en.js,sha256=voemtT8vOEBMD8l7bQc3woTFMggmTJQtHujmclD0JBM,7155
45
+ tortoise_orm_studio/static/i18n.js,sha256=8h7QtlBuYJ8smVe3vX1-s_Ix38Or2VWc7YB9n4oBtJ4,4740
46
+ tortoise_orm_studio/static/i18n.zh-CN.js,sha256=uSHZ1pVVOd9DJqvptAYYRACypu5WzwOLvVMvWiQGr90,7316
47
+ tortoise_orm_studio/static/index.html,sha256=3GnJavmJVv67KtukC5tXC19zEzHGVUq_kqzBT1_2pXo,28311
48
+ tortoise_orm_studio/static/inline-edit.js,sha256=WrOjJuAsMOHmks-75U86palP0EF6Z3C97-PxDDYodf4,3914
49
+ tortoise_orm_studio/static/json-view.js,sha256=C0efBsiQ17OYqbCkXPrT26kh-aovJ_LhLBWIMGiQ5HE,6123
50
+ tortoise_orm_studio/static/migrations.js,sha256=V3XquFu9FlhXOtIt5IXPa7ksrTHIoQ3ZHlEnjq-zjuY,4674
51
+ tortoise_orm_studio/static/palette.js,sha256=7yBv8d6WkXTh3bgZSuCkrYqBbz9v9NoW4yQ0RMgZ4n0,5944
52
+ tortoise_orm_studio/static/pending.js,sha256=Dibks2c1VaVh_bMJk7as-x778Wl8KgQDVS_SyRncjx4,8788
53
+ tortoise_orm_studio/static/pickers.js,sha256=ES-4xiPlKm6yp2kPGRllQxLmjOawlsapYrX3PqPi5Zw,8197
54
+ tortoise_orm_studio/static/playground.js,sha256=72JPdSQnF1jVgg-_T5HJ3Uzf876tM15X3Ru5n9u1a9s,3702
55
+ tortoise_orm_studio/static/query-history.js,sha256=3Y8W-BlCXSPsKUpci5zLeUao5YRJDvxPJ48OkdWRtlQ,2672
56
+ tortoise_orm_studio/static/shortcuts.js,sha256=81rrBw3cUZyBxemJuLIeJ3WuJQtYWo_ycraQjHM-QA4,5679
57
+ tortoise_orm_studio/static/state-hash.js,sha256=PMo27WPYvnYO4Rpc24GPjcZJM_7Y_x63ReHKr7eLsZM,4062
58
+ tortoise_orm_studio/static/tabs.js,sha256=v8XP8Mi_SMT6zPSxk9rvVwQkXYptZBDpjxsomYmgEAY,12721
59
+ tortoise_orm_studio/static/theme-init.js,sha256=NQ0ZSv2cZzDiX7YsRJkxxeVGYC1DeBhnQgYVnUEUZiM,1122
60
+ tortoise_orm_studio/static/theme.js,sha256=KGWSC7HSD2niRiP4rA7zCBIfIwRYvjcDnbfz-8NDpt8,3150
61
+ tortoise_orm_studio/static/toasts.js,sha256=JzhVJCO84Lqueais3eYQCCqzXfND3r3h3bDc8kBfvAc,2560
62
+ tortoise_orm_studio/static/views.js,sha256=C2QW--UcXD9VMgVS122wZZJxs1czR_uslzfyvIggQo4,2000
63
+ tortoise_orm_studio/static/widgets.js,sha256=0T1Y5Er-1iyP0nIB0f5usvaRyDPPcjAK9Z_8b8PYexI,11596
64
+ tortoise_orm_studio-1.0.0.dist-info/METADATA,sha256=NOv_6kjLXP0UsdBcpxXCwcBBhhMMcqYtt54o-mrZ6C8,11606
65
+ tortoise_orm_studio-1.0.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
66
+ tortoise_orm_studio-1.0.0.dist-info/entry_points.txt,sha256=8IdzZs7_GbyPZ7PyPaIKkig6hEOUjAK9-MvST3_ote0,69
67
+ tortoise_orm_studio-1.0.0.dist-info/licenses/LICENSE,sha256=MujTdvQoiAobOWKrdbkKvifh5Gy10GHvHkQTJ6kmop4,712
68
+ tortoise_orm_studio-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ tortoise-orm-studio = tortoise_orm_studio.cli:main