Python — storage, net, ui
freshgram.storage (storage.private)
Section titled “freshgram.storage (storage.private)”| Method | Description |
|---|---|
get(key, default=None) |
the value or default |
set(key, value) |
write; values are CBOR types (numbers, strings, bytes, lists, dicts) |
delete(key) |
delete |
keys(prefix="", limit=100) |
keys by prefix (sorted; limit below 1 is Invalid, over 1000 is cut to 1000) |
usage() |
{used, quota, keys} |
freshgram.net
Section titled “freshgram.net”| Method | Permissions | Description |
|---|---|---|
fetch(url, method="GET", headers=None, body=None, timeout=10000) |
net.https |
a request; returns Response |
get(url, **opts) / post(url, body=None, **opts) |
net.https |
shortcuts |
tcp(host, port, tls=False, timeout=10000) |
net.tcp |
Socket |
udp(host, port, timeout=10000) |
net.udp |
Socket |
ws(url, protocols=None, headers=None, timeout=10000) |
net.ws |
WebSocket (wss:// only) |
Socket (from tcp / udp; attribute id):
send(data, timeout=10000)returns the number of bytes sent;recv(max_bytes=65507, timeout=1000)returns(data, closed);datais empty when nothing arrived in time;close().
WebSocket (attributes id, protocol):
send(data, timeout=10000)sends astras a text frame orbytesas a binary frame (up to 1 MiB) and returns the number of bytes sent;recv(timeout=1000)returns{"kind": "text" | "binary" | "close" | "none", "data", "closed"}("close"addscodeandreason);close(code=1000, reason="").
Both support with (closes on exit) and, for objects opened through aio, async with. With aio, send, recv and close return awaitables. Timeouts are in milliseconds.
freshgram.Response: status, headers, header_list, body (bytes), text(encoding="utf-8") (decodes with replacement characters), json(), ok (status 200 to 299).
net.fetch sends method as is: text up to 8 bytes that is not an allowed method is Invalid, but a value that is not text or is over 8 bytes silently becomes GET. A non-integer timeout is replaced by the default, a number out of range is clamped. See Network operations.
freshgram.ui
Section titled “freshgram.ui”| Method | Description |
|---|---|
toast(text, action=None, label=None, undo=False, duration=None, title=None) |
a toast; undo=True needs an action (otherwise Invalid: “undo needs an action”) |
open_settings() |
open the plugin’s settings page (from a click) |
settings_page(title, items, buttons=None) |
describe the settings page |
dialog(title, items, buttons=None) / close_dialog() |
a dialog |
window(window_id, title, items, buttons=None, mode="layer") |
a window (layer or window) |
update_window(window_id, title, items, buttons=None) / close_window(window_id) |
update / close a window |
See UI.
freshgram.timers
Section titled “freshgram.timers”set(timer_id, seconds, repeat=False), clear(timer_id), list(). Up to 32 timers, from 1 second to 7 days. Timers need no permission.
freshgram.plugins
Section titled “freshgram.plugins”send(to, data=None), peers() — messaging between plugins (plugins.message).
