Message broker for the digital campus.
Note: campus-yapper
is not yet published on PyPI, hence installation via pip
is not yet supported.
First, clone the repository:
git clone https://github.com/nyjc-computing/yapper-python
Then, install the package using poetry
:
cd yapper-python
poetry install
Yapper uses environment variables for configuration and automatically selects the appropriate backend based on your environment.
Set the following environment variables:
export CLIENT_ID="your_unique_client_id"
export CLIENT_SECRET="your_client_secret"
export ENV="development" # development, testing, staging, or production
- development/testing: Uses SQLite backend (suitable for local development)
- staging/production: Uses PostgreSQL backend (suitable for production deployments)
import campus_yapper
# Create yapper instance (backend determined by ENV variable)
yapper = campus_yapper.create()
@yapper.on_event('google.forms.submit')
def on_google_forms_submit(event: Event) -> None:
"""Handle event when a google form is submitted"""
# Assume event has a `data` attribute containing event data
user = event.data['email']
cca = event.data['cca']
# Assuming successful form submission adds user to the CCA
yapper.emit(
'campus.circles.user.add',
data={'user': user, 'circle': cca}
)
# Begin listening for events and handling them
yapper.run()
# Optional: specify custom database file
yapper = campus_yapper.create(db="./my_app.db")
# Default: uses in-memory database (":memory:")
# db_uri parameter is required for staging/production environments
yapper = campus_yapper.create(db_uri="postgresql://user:pass@host:5432/database")
# No default value - you must explicitly specify the connection URI
Dynamic event handler registration is not yet designed, but is on the roadmap.
- Event-driven architecture for the digital campus.
- Easy-to-use API for emitting and handling events.
- Supports custom event handlers.