Skip to content

Connections and usage with the Python SDK ​

client.workspaces has four methods: list connections, refresh one, get a reconnect link, and read usage. It cannot manage members, invitations or API keys.

How do I list connection slugs in Python? ​

python
import os

for c in client.workspaces.list_connections(os.environ["SOCIFYR_WORKSPACE_ID"]):
    print(c["slug"], c["platform"], c.get("status"), c.get("expiresAt"))

Each item has id, slug, platform, platformUsername, targetName, connectedAt, expiresAt, status (active, expiring, needs_reconnect), canRefresh and hasRefreshToken. See connection concepts.

How do I refresh an expiring connection? ​

python
res = client.workspaces.refresh_connection(workspace_id, "x-myhandle")
print(res["status"], res["expiresAt"])

connection is a slug or ID. When the platform cannot refresh or there is no refresh token, the API returns 400 (for example No refresh token available. Please reconnect instead.) and the SDK raises ValidationError.

How do I reconnect an expired account? ​

python
link = client.workspaces.reconnect_link("x-myhandle")
print(link["url"], link["expiresIn"])  # single-use, short-lived

Give the URL to the account owner. After they authorize, the same connection and slug keep working.

How do I fix every unhealthy connection? ​

python
for c in client.workspaces.list_connections(workspace_id):
    if c.get("status") == "active":
        continue
    if c.get("canRefresh"):
        client.workspaces.refresh_connection(workspace_id, c["slug"])
    else:
        print("Reconnect", c["slug"], client.workspaces.reconnect_link(c["slug"])["url"])

How do I check plan usage? ​

python
usage = client.usage()            # same as client.workspaces.usage()
print(usage["tier"], usage["uploads"], usage["accounts"])

Returns tier, uploads, accounts, xPosts, xSpendUsd and storage. Each dimension has used, limit, remaining and unlimited; limit and remaining are None when unlimited.

What is missing compared with the TypeScript SDK? ​

Workspace create, rename, delete, members, invitations, API keys with guardrails, and connection disconnect, fork and target methods. See TypeScript workspaces and connections.

Next steps ​