Skip to content

nyjc-computing/yapper-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yapper-python

Message broker for the digital campus.

Installation

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

Usage

Yapper uses environment variables for configuration and automatically selects the appropriate backend based on your environment.

Environment Variables

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)

Basic Usage

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()

Backend-Specific Configuration

SQLite (Development/Testing)

# Optional: specify custom database file
yapper = campus_yapper.create(db="./my_app.db")
# Default: uses in-memory database (":memory:")

PostgreSQL (Staging/Production)

# 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.

Features

  • Event-driven architecture for the digital campus.
  • Easy-to-use API for emitting and handling events.
  • Supports custom event handlers.

About

Message broker for the digital campus

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •