Skip to main content

magic-campus-sdk

Python SDK and CLI for MagicCampus platform integrations. IM remains a supported domain, and this repository keeps the bundled OpenIM transport inside magiccampus_sdk.

This project removes direct user-facing dependency on OpenIM token and endpoint configuration. You only configure:

  • apiurl
  • apikey
  • platform

At runtime, IM-backed flows call:

GET /api/v1/accounts/imToken?platform=<PLATFORM>

and uses the response fields:

  • userId
  • imToken
  • wsApi
  • httpApi

Install locally

uv sync

This repository vendors only the OpenIM transport pieces that magiccampus_sdk actually uses, and layers platform-facing SDK / CLI commands on top.

IM-specific low-level internals, models, and protobufs now live under magiccampus_sdk.im.

CLI quick start

magic-campus --help
magic-campus config init --apiurl https://api-test.pearlapi.com --apikey "$MAGICCAMPUS_APIKEY" --platform IOS --default true
magic-campus auth status --format pretty
magic-campus im notify send --to user:10134002 --text "hello"
magic-campus im notify send --to user:10134002 --markdown "# title\n\nbody"
magic-campus im notify send --to user:10134002 --custom '{"data":"{\"customType\":1}","extension":"example","description":"example custom message"}'
magic-campus im notify send --to user:10134002 --custom '{"customType":503,"data":{"title":"title","subTitle":"subTitle","schema":"https://example.com/playground"}}' --cover-image /path/to/playground.jpg
magic-campus im notify send-link-card --to user:10134002 --title "title" --sub-title "subTitle" --schema "https://example.com/playground" --cover-image /path/to/playground.jpg
magic-campus im notify send-link-card --to user:10134002 --title "title" --sub-title "subTitle" --schema "https://example.com/playground" --cover-image https://example.com/playground.jpg
magic-campus space get --group group_123 --format pretty
magic-campus space list-notice --space space_123 --format table
magic-campus space list-notice --group group_123 --format table
magic-campus space create-notice --space space_123 --title "Maintenance" --text "Starts at 22:00" --expiretime 1785510000000
magic-campus space create-notice --group group_123 --title "Maintenance" --text "Starts at 22:00" --expiretime 1785510000000
magic-campus space group update-name --group group_123 --name "New group name"
magic-campus user get --id 10134002 --format pretty
magic-campus user list --all --academy-code Nature --fields userId,nickname,email --format table
magic-campus user list --random --fields userId,nickname --format table
magic-campus user update-profile --id 10134002 --nickname "New Name" --avatar-url "https://cdn.example.com/avatar.png"
magic-campus user update-profile --id 10134002 --avatar-url "" # restore the default avatar
magic-campus user get-growth-profile --id 10134002 --format pretty
magic-campus user init-growth-profile --id 10134002 --reset false
magic-campus user set-academy --id 10134002 --academy-code Nature
magic-campus user adjust-elements --id 10134002 --metal-delta 5 --water-delta -2

send-link-card returns only ok, serverMsgID, and sendTime by default. Add --debug for the full send result. For an HTTP(S) cover URL, the CLI reads its image dimensions and keeps that URL in the card without uploading a copy.

magic-campus config init also supports an interactive TTY flow when you omit auth flags.

im notify send sends over MagicCampus HTTP POST /agent/v1/im/sendMessage. im notify history still relies on the websocket transport and local sync database.

Legacy compatibility commands remain available:

magic-campus notify +send --to user:10134002 --text "hello"
magic-campus notify +history --to user:10134002

CLI config is stored at:

~/.magic-campus/auth/magiccampus-im-sdk.json

Supported commands:

  • config init|list|use|remove
  • auth status
  • im notify send
  • im notify history
  • space get
  • space list-notice (--space <spaceId> | --group <groupId>)
  • space create-notice (--space <spaceId> | --group <groupId>)
  • space group update-name
  • user get
  • user list (--all | --random) [--fields <field1,field2>] [--academy-code <code>]
  • user update-profile --id <userId> [--nickname <name>] [--avatar-url <url>]
  • user get-growth-profile --id <userId>
  • user init-growth-profile --id <userId> [--reset <true|false>]
  • user set-academy --id <userId> --academy-code <Material|Digital|Sound|Movement|Nature|Healing>
  • user adjust-elements --id <userId> [--metal-delta <int>] [--wood-delta <int>] [--water-delta <int>] [--fire-delta <int>] [--earth-delta <int>]
  • feed list
  • notify +send (compat)
  • notify +history (compat)

Python SDK quick start

from magiccampus_sdk import MagicCampusConfig, MagicCampusSDK

sdk = MagicCampusSDK(
    MagicCampusConfig(
        apiurl="https://api-test.pearlapi.com",
        apikey="YOUR_API_KEY",
        platform="IOS",
    )
)

space = sdk.get_space_by_group_id("GROUP_ID")
print(space.id)
print(space.name)
print(space.introduction)

Python websocket quick start

from magiccampus_sdk import MagicCampusWSSDK, MagicCampusWSConfig

sdk = MagicCampusWSSDK(
    MagicCampusWSConfig(
        apiurl="https://api-test.pearlapi.com",
        apikey="YOUR_API_KEY",
        platform="IOS",
        data_dir="./magiccampus_data",
    )
)

space = sdk.get_space_by_group_id("GROUP_ID")
print(space.name)

sdk.login()
sdk.start()
sdk.send_text("hello", recv_id="10134002")
sdk.send_markdown("# title\n\nbody", recv_id="10134002")

group = sdk.get_group_info("GROUP_ID")
print(group["groupName"])

groups = sdk.get_groups_info(["GROUP_ID_1", "GROUP_ID_2"])

Runnable examples live in magiccampus_sdk/example.py and magiccampus_sdk/example_ws.py.

CLI smoke script

An executable smoke helper lives at scripts/smoke_cli.py.

Offline-safe mode only exercises config persistence and notify dry-run:

uv run python scripts/smoke_cli.py

This mode does not require a real API key. It uses a placeholder key by default and avoids any live auth call.

Real network mode

To run the live auth probe, provide a real API key and enable --live:

export MAGICCAMPUS_APIURL=https://api-test.pearlapi.com
export MAGICCAMPUS_APIKEY='your real api key'
export MAGICCAMPUS_PLATFORM=IOS
uv run python scripts/smoke_cli.py --live

Optional variables:

  • MAGICCAMPUS_SMOKE_TARGET: target used by dry-run and optional live send, default user:smoke-target
  • MAGICCAMPUS_PLATFORM: defaults to IOS

If you also want to send a real text message, set a real target and pass --live-send:

export MAGICCAMPUS_SMOKE_TARGET='user:10134002'
uv run python scripts/smoke_cli.py --live --live-send --text 'hello from smoke script'

--live-send performs a real outbound send, so use it only with a valid target and credentials.

Notes

  • apiurl can point to any MagicCampus API base URL; IM-backed flows append /api/v1/accounts/imToken
  • client.user.get(...) calls GET /api/v1/accounts/getUserInfo with apiurl and apikey directly
  • platform defaults to IOS
  • low-level IM send / receive behavior comes from the bundled transport modules inside magiccampus_sdk
  • the wrapper does not persist raw OpenIM credentials in CLI config

Metadata

Release files for magic-campus-sdk 0.2.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for magic-campus-sdk 0.2.17
File Size Uploaded
magic_campus_sdk-0.2.17.tar.gz 106.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for magic-campus-sdk 0.2.17
File Interpreter ABI Platform
magic_campus_sdk-0.2.17-py3-none-any.whl Python 3 none any Details

Total release size: 205.9 kB

Release files / magic_campus_sdk-0.2.17.tar.gz

Download URL magic_campus_sdk-0.2.17.tar.gz
Size 106.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6a41be3c71a666fd88ca0b76b82f9389dd50b43e42767ba823e5a5075c730e61
BLAKE2b-256 checksum
How to use checksums
022d869430b99d8348f5e16a31c7db500e454d3ac237e00e7695d9141bcbff3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.12

Release files / magic_campus_sdk-0.2.17-py3-none-any.whl

Download URL magic_campus_sdk-0.2.17-py3-none-any.whl
Size 99.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9feac1dde05cfd55f21351d3ca861f7a05434d22763a4b207b4a390293f5890e
BLAKE2b-256 checksum
How to use checksums
3fec17467a1c65e467453fce0d211c51eecff19e14dffd62b73593fa57685d1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.2.17 This release

2 release files

0.2.16

2 release files

0.2.15

2 release files

0.2.14

2 release files

0.2.13

2 release files

0.2.12

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page