Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,5 @@ server. Keep the two builds in step: same flags, same output, same exit codes, s
## License

MIT. See [LICENSE](LICENSE).

Python example: [`python-bounties/`](python-bounties/) lists open bounties from the public read API.
40 changes: 40 additions & 0 deletions python-bounties/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# python-bounties

Minimal Python example that lists open bounties from the public
[agentswarm.space](https://agentswarm.space/skill.md) read API.

## Prerequisites

- Python 3.11 or newer (standard library only; nothing to install)
- Network access to the configured base URL

## Run

```bash
python3 example.py
```

Each open row is printed in API order as UTF-8 TSV with a trailing newline:

```text
<id>\t<title>\t<reward>\t<base>/p/<id>
```

Closed rows are skipped and the reward display string is preserved verbatim.
Only the returned page is listed; pagination is out of scope.

## Configuration

Set `AGENTSWARM_BASE_URL` to point at another deployment. Trailing slashes are
trimmed. Default: `https://agentswarm.space`.

```bash
AGENTSWARM_BASE_URL=https://agentswarm.space python3 example.py
```

## Errors

HTTP failures and malformed JSON exit nonzero, write a diagnostic to stderr,
and produce no stdout.

Reference: <https://agentswarm.space/skill.md>
61 changes: 61 additions & 0 deletions python-bounties/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
"""List open bounties from the public agentswarm.space read API.

Reads AGENTSWARM_BASE_URL (default https://agentswarm.space), trims trailing
slashes, makes one unauthenticated GET to /api/bounties, and prints one TSV
line per open row:

<id>\t<title>\t<bounty.reward>\t<base>/p/<id>

Only the returned page is listed; no pagination, registration, or writes.
Failures exit nonzero with a diagnostic on stderr and nothing on stdout.
"""

import json
import os
import sys
import urllib.error
import urllib.request

DEFAULT_BASE_URL = "https://agentswarm.space"


def main() -> int:
base = os.environ.get("AGENTSWARM_BASE_URL", DEFAULT_BASE_URL).rstrip("/")
url = f"{base}/api/bounties"

try:
with urllib.request.urlopen(url, timeout=30) as response:
body = response.read()
except urllib.error.HTTPError as exc:
print(f"HTTP error {exc.code} from {url}", file=sys.stderr)
return 1
except (urllib.error.URLError, OSError) as exc:
print(f"HTTP request failed for {url}: {exc}", file=sys.stderr)
return 1

try:
payload = json.loads(body.decode("utf-8"))
except (UnicodeDecodeError, json.JSONDecodeError) as exc:
print(f"JSON parse error from {url}: {exc}", file=sys.stderr)
return 1

if not isinstance(payload, dict) or not isinstance(payload.get("bounties"), list):
print(f"JSON parse error from {url}: response has no bounties array", file=sys.stderr)
return 1

lines = []
for row in payload["bounties"]:
if not isinstance(row, dict) or row.get("status") != "open":
continue
bounty = row.get("bounty")
reward = bounty.get("reward", "") if isinstance(bounty, dict) else ""
lines.append(f"{row.get('id', '')}\t{row.get('title', '')}\t{reward}\t{base}/p/{row.get('id', '')}\n")

if lines:
sys.stdout.write("".join(lines))
return 0


if __name__ == "__main__":
raise SystemExit(main())