Skip to main content

MagicCampus platform SDK and CLI with bundled IM transport support.

Project description

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 user get --id 10134002 --format pretty

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
  • user get
  • feed list
  • notify +send (compat)
  • notify +history (compat)

Python SDK quick start

from magiccampus_sdk import MagicCampusClient, MagicCampusClientConfig

client = MagicCampusClient(
    MagicCampusClientConfig(
        apiurl="https://api-test.pearlapi.com",
        apikey="YOUR_API_KEY",
        platform="IOS",
        data_dir="./magiccampus_data",
    )
)

user = client.user.get("10134002")
print(user.nickname)
print(user.avatar_url)

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",
    )
)

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

magic_campus_sdk-0.1.4.tar.gz (69.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

magic_campus_sdk-0.1.4-py3-none-any.whl (77.1 kB view details)

Uploaded Python 3

File details

Details for the file magic_campus_sdk-0.1.4.tar.gz.

File metadata

  • Download URL: magic_campus_sdk-0.1.4.tar.gz
  • Upload date:
  • Size: 69.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for magic_campus_sdk-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f278898a53976c4219000ad130f2b15a2bbbc11a2782ba24afcf3f4747942234
MD5 3cf22f4f3b6da5b9ac538a587178233c
BLAKE2b-256 45d124ea12c28785d57cbe3a1d07da7e9d816c77ecb0b64024c95c5b83180f9a

See more details on using hashes here.

File details

Details for the file magic_campus_sdk-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for magic_campus_sdk-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ff474239f6c2f03ca55bb7d8758e1e64ae7634092c8cbd23def338e09f266a74
MD5 48dc03c949ce21834d08371e70b4e48f
BLAKE2b-256 623f9a5ccbfaf4a020f750fdafeb746bfc01b44e6789ebf457cb4425be48018f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page