Python client library for NYJC Campus API, providing unified access to campus services including authentication, assignments, circles, submissions, and timetable management.
The Campus API Python library is a comprehensive client for interacting with the NYJC Campus backend services. It provides a unified interface for server-to-server and device-based authentication, enabling secure access to various campus resources through a consistent API.
- Unified client interface for all Campus services
- Support for server-to-server and device authentication modes
- OAuth2 integration with Google Workspace (nyjc.edu.sg domain)
- Comprehensive API coverage for assignments, circles, submissions, and timetable
- Session management and secure request handling
- Error handling and logging support
- Language: Python 3.11
- Package Management: Poetry
- Dependencies:
flask- Web framework (for integration)campus-suite- Campus backend services- Additional dependencies managed via Poetry
- Python 3.11
- Poetry
- Access to Campus development environment (for server mode)
-
Clone the repository (if not already done):
git clone https://github.com/nyjc-computing/campus-api-python.git cd campus-api-python -
Install dependencies:
poetry install
-
Configure environment variables (for server mode):
Set the following environment variables:
# Campus OAuth credentials (required for server mode) CLIENT_ID=your-client-id CLIENT_SECRET=your-client-secret
Import and initialize the client:
from campus_python import Campus
# For server-to-server communication
client = Campus(timeout=30, mode="server")
# For device/public clients
client = Campus(timeout=30, mode="device")campus-api-python/
├── campus_python/ # Main package
│ ├── __init__.py # Main Campus client class
│ ├── errors.py # Error handling
│ ├── interface.py # Core interfaces
│ ├── api/
│ │ └── v1/ # API service clients
│ │ ├── assignments.py
│ │ ├── circles.py
│ │ ├── submissions.py
│ │ └── timetable.py
│ ├── auth/
│ │ └── v1/ # Authentication clients
│ │ ├── clients.py
│ │ ├── credentials.py
│ │ ├── logins.py
│ │ ├── oauth.py
│ │ ├── root.py
│ │ ├── sessions.py
│ │ ├── users.py
│ │ └── vaults.py
│ └── json_client/ # JSON client implementation
│ ├── __init__.py
│ └── interface.py
├── scripts/ # Utility scripts
│ └── refresh-dependencies.sh
├── tests/ # Test suite
│ └── unit/ # Unit tests
├── pyproject.toml # Poetry configuration
└── README.md # This file
- Server Mode: For server-to-server communication. Requires
CLIENT_IDandCLIENT_SECRETenvironment variables. - Device Mode: For public clients (e.g., CLI tools). No credentials required; limited to public endpoints.
| Variable | Required | Mode | Description |
|---|---|---|---|
CLIENT_ID |
Yes | Server | OAuth client ID from Campus auth |
CLIENT_SECRET |
Yes | Server | OAuth client secret from Campus auth |
If you make changes to the local campus-suite package:
./scripts/refresh-dependencies.shThis will update poetry.lock and reinstall dependencies from the latest commits.
Run the test suite:
poetry run pytestUnit tests are located in tests/unit/.
The project uses Ruff for linting and formatting:
poetry run ruff check .
poetry run ruff format .Ensure dependencies are installed:
poetry installFor server mode, verify CLIENT_ID and CLIENT_SECRET are set correctly.
Check network connectivity and Campus service availability.
- Follow the existing code style (enforced by Ruff)
- Add unit tests for new features
- Update documentation as needed
- Commit with descriptive messages
- campus - Campus backend services
- campus-suite - Campus suite components
Internal use by NYJC Computing team.