Network
A plugin has no network sockets. All connections are opened by the app.
| Permission | What it gives |
|---|---|
net.https |
HTTPS requests with net.fetch |
net.ws |
secure WebSockets (wss://) |
net.tcp |
TCP, optionally with TLS |
net.udp |
a UDP socket bound to one address |
net.local |
loopback only (localhost, 127.0.0.0/8, ::1), only the listed ports |
r = freshgram.net.get("https://example.org/api")if r.ok: data = r.json()
freshgram.net.post("https://example.org/api", body=b"{}", headers={"Content-Type": "application/json"})Response has status, headers, header_list, body, plus text(), json() and ok. The default timeout is 10,000 ms.
Sockets
Section titled “Sockets”with freshgram.net.tcp("example.org", 443, tls=True) as s: s.send(b"...") data, closed = s.recv(max_bytes=4096, timeout=1000)Hosts may be names or public IPs; local and private addresses are refused (except with net.local).
WebSocket
Section titled “WebSocket”ws = freshgram.net.ws("wss://example.org/feed", protocols=["v1"])msg = ws.recv(timeout=1000) # {"kind": "text" | "binary" | "close" | "none", ...}ws.send("hello")ws.close()Messages are up to 1 MiB; the host answers pings itself.
Messages between plugins
Section titled “Messages between plugins”Permission plugins.message. The receiver must list the sender (or "*") in contributes.messages.from:
freshgram.plugins.send("com.example.other", {"hello": 1})
@freshgram.on_plugin_message("com.example.sender")def got(sender, data): ...