English
Big data: files, images, binary
The channel is for small, structured data you need to act on right away. For images, PDFs, video, exported files, multi-MB logs, going through the channel means base64 first (+33% size), then JSON, then a copy on each side. Axon's answer: Python registers the bytes as a URL, the browser fetches it directly — the payload never touches the channel.
| Through the channel | Through an axon:// URL | |
|---|---|---|
| 1 MB binary | 1.33 MB after base64, copied twice | the original 1 MB, read by Chromium |
| 5 MB image | jank, double memory | renders, streams |
| Video | basically impossible | <video src> works (seeking not supported yet) |
| Frontend code | await data, convert to blob | hand the URL to src / fetch |
Python side
controller/Report.py
python
from axon import module axon.AxonAssetAxonAsset, AxonController(web_name: str | list[str] = '*', id: Optional[str] = None, shared: bool = False)
``AxonController`` 的命名空间对象:既能当装饰器用,也挂注册表操作。AxonController
@AxonController(web_name: str | list[str] = '*', id: Optional[str] = None, shared: bool = False)
``AxonController`` 的命名空间对象:既能当装饰器用,也挂注册表操作。AxonController("MainView")
class class ReportReport:
def chart_url(self) -> str:
png = build_chart_png() # your own bytes
return module axon.AxonAssetAxonAsset.from_bytes(data: bytes | bytearray | memoryview, name: str = 'blob', mime: str | None = None) -> strfrom_bytes(png, name="chart.png") # → axon://asset/<token>/chart.png
def export_url(self) -> str:
return module axon.AxonAssetAxonAsset.from_file(path: str | pathlib.Path, name: str | None = None, mime: str | None = None) -> strfrom_file("/tmp/report.pdf") # file stays on disk
def drop(self, url: str) -> bool:
return module axon.AxonAssetAxonAsset.release(url_or_token: str) -> boolrelease(url) # optional: free it early| Function | Purpose |
|---|---|
AxonAsset.from_bytes(data, name="blob", mime=None) | bytes → URL; mime is guessed from the name |
AxonAsset.from_file(path, name=None) | local file → URL (not read into memory; opened per request) |
AxonAsset.release(url) / clear() / count() | release / clear all / how many are held |
The URL looks like axon://asset/<token>/<filename>: the token selects the content, the filename only drives Content-Type and the default download name.
JS side
Once you have the URL it is plain web code — no Axon API involved:
js
const const url: anyurl = await const Axon: {
DemoController: {
add(a: number, b: number): Promise<number>;
asset_count(): Promise<number>;
blob(size?: number): Promise<string>;
broadcast(text: string): Promise<Array<any>>;
call_js_mirror(payload: any): Promise<any>;
cross_broadcast(text?: string): Promise<Record<string, any>>;
cross_call(text?: string): Promise<any>;
cross_close(): Promise<Array<string>>;
cross_emit(text?: string): Promise<Array<string>>;
cross_open(): Promise<Array<string>>;
delayed(msg: string, ms?: number): Promise<string>;
... 13 more ...;
counter: number;
};
}
Axon 的 JS 侧语法糖。
tsawait Axon.Users.add(1, 2) // 调 Python 方法, 位置参数直接摊开
await Axon.Users.slow([1000], {}, 300) // 需要 kwargs / 超时时用打包写法
await Axon.Users.count // 读 Python 属性 (getVar)
Axon.Users.count = 3 // 写 Python 属性 (setVar, fire-and-forget)
属性读是惰性的: 只有真正 await / .then / .catch / .finally 时才发请求。
取到的 dispatcher 本身是函数, 同时挂了 then/catch/finally,
让 Axon.Users.count 既能当 Promise 用, 又能当方法调用。
Axon.Report.chart_url();
var document: Documentwindow.document returns a reference to the document contained in the window.
document.ParentNode.querySelector<Element>(selectors: string): Element | null (+4 overloads)Returns the first element that is a descendant of node that matches selectors.
querySelector("#chart").src = const url: anyurl; // <img src="axon://asset/…">js
const const url: anyurl = await const Axon: {
DemoController: {
add(a: number, b: number): Promise<number>;
asset_count(): Promise<number>;
blob(size?: number): Promise<string>;
broadcast(text: string): Promise<Array<any>>;
call_js_mirror(payload: any): Promise<any>;
cross_broadcast(text?: string): Promise<Record<string, any>>;
cross_call(text?: string): Promise<any>;
cross_close(): Promise<Array<string>>;
cross_emit(text?: string): Promise<Array<string>>;
cross_open(): Promise<Array<string>>;
delayed(msg: string, ms?: number): Promise<string>;
... 13 more ...;
counter: number;
};
}
Axon 的 JS 侧语法糖。
tsawait Axon.Users.add(1, 2) // 调 Python 方法, 位置参数直接摊开
await Axon.Users.slow([1000], {}, 300) // 需要 kwargs / 超时时用打包写法
await Axon.Users.count // 读 Python 属性 (getVar)
Axon.Users.count = 3 // 写 Python 属性 (setVar, fire-and-forget)
属性读是惰性的: 只有真正 await / .then / .catch / .finally 时才发请求。
取到的 dispatcher 本身是函数, 同时挂了 then/catch/finally,
让 Axon.Users.count 既能当 Promise 用, 又能当方法调用。
Axon.Report.export_url();
const const buf: ArrayBufferbuf = await (await function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>fetch(const url: anyurl)).Body.arrayBuffer(): Promise<ArrayBuffer>arrayBuffer(); // 1 MB in a few ms
var console: Consoleconsole.Console.log(...data: any[]): voidThe console.log() static method outputs a message to the console.
log(const buf: ArrayBufferbuf.ArrayBuffer.byteLength: numberRead-only. The length of the ArrayBuffer (in bytes).
byteLength);js
const const url: anyurl = await const Axon: {
DemoController: {
add(a: number, b: number): Promise<number>;
asset_count(): Promise<number>;
blob(size?: number): Promise<string>;
broadcast(text: string): Promise<Array<any>>;
call_js_mirror(payload: any): Promise<any>;
cross_broadcast(text?: string): Promise<Record<string, any>>;
cross_call(text?: string): Promise<any>;
cross_close(): Promise<Array<string>>;
cross_emit(text?: string): Promise<Array<string>>;
cross_open(): Promise<Array<string>>;
delayed(msg: string, ms?: number): Promise<string>;
... 13 more ...;
counter: number;
};
}
Axon 的 JS 侧语法糖。
tsawait Axon.Users.add(1, 2) // 调 Python 方法, 位置参数直接摊开
await Axon.Users.slow([1000], {}, 300) // 需要 kwargs / 超时时用打包写法
await Axon.Users.count // 读 Python 属性 (getVar)
Axon.Users.count = 3 // 写 Python 属性 (setVar, fire-and-forget)
属性读是惰性的: 只有真正 await / .then / .catch / .finally 时才发请求。
取到的 dispatcher 本身是函数, 同时挂了 then/catch/finally,
让 Axon.Users.count 既能当 Promise 用, 又能当方法调用。
Axon.Report.export_url();
const const a: HTMLAnchorElementa = var document: Documentwindow.document returns a reference to the document contained in the window.
document.Document.createElement<"a">(tagName: "a", options?: ElementCreationOptions): HTMLAnchorElement (+2 overloads)In an HTML document, the document.createElement() method creates the HTML element specified by localName, or an HTMLUnknownElement if localName isn't recognized.
createElement("a");
const a: HTMLAnchorElementa.HTMLHyperlinkElementUtils.href: stringhref = const url: anyurl;
const a: HTMLAnchorElementa.HTMLAnchorElement.download: stringThe HTMLAnchorElement.download property is a string indicating that the linked resource is intended to be downloaded rather than displayed in the browser. The value, if any, specifies the default file name for use in labeling the resource in a local file system. If the name is not a valid file name in the underlying OS, the browser will adjust it.
download = "report.pdf";
const a: HTMLAnchorElementa.HTMLElement.click(): voidThe HTMLElement.click() method simulates a mouse click on an element. When called on an element, the element's click event is fired (unless its disabled attribute is set).
click();`
Python makes 2 MB of bytes, registers them as a URL, and the frontend fetches them: the message stream above shows the URL, the byte count and the time — nothing went through the channel.
Watch out for
Lifetime is automatic
Nothing to manage by default: assets idle for 10 minutes are dropped, and once the byte total exceeds 256 MB the least-recently-used ones are evicted (from_file() assets hold no memory, only a path). To tune:
AxonAsset.configure(ttl=300, budget=64 << 20) # seconds / bytes; <=0 disables
AxonAsset.release(url) # when you really want it gone nowRange is supported (video seeks)
axon:// serves partial content: when the media stack asks with Range: bytes=… the framework answers 206 Partial Content with a correct Content-Range, so video seeking, progressive playback and resumable downloads work. Two boundaries:
- Multi-range requests (
Range: bytes=0-99,200-299) are not implemented as multipart; they fall back to a full200body, which RFC 7233 allows. - Out-of-bounds ranges (start past the end) are rejected with
400on purpose: letting Qt seek past EOF aborts the renderer process.
When to stay on the channel
Small structured data (one screen of a list, tens of KB of JSON) is simpler through the channel — no lifetime to manage. Use URLs only for "big" or "binary".
Relation to compression
Strings larger than 256 KB are gzipped automatically across the channel, so big text payloads are handled for you; bytes go through axon://. The two are complementary.