The Penn SDK

Release v1.6.7.

Penn SDK is the Python library for writing code that interfaces with University of Pennsylvania data. It consists of wrappers for the Registrar, Dining, and Directory API’s

Contents:

Registrar API Wrapper

This documentation explains the methods of the Registrar object. For the specific fields on the objects returned by these methods, see the official documentation.

Note

The Penn Data Warehouse performs nightly maintenance, which causes downtime for Penn InTouch and the Penn OpenData Registrar API. This will throw an APIError in the SDK, which client applications can catch and try to fetch the data again later.

class penn.registrar.Registrar(bearer, token)[source]

The client for the Registrar. Used to make requests to the API.

Parameters:
  • bearer – The user code for the API
  • token – The password code for the API

Usage:

>>> from penn import Registrar
>>> r = Registrar('MY_USERNAME_TOKEN', 'MY_PASSWORD_TOKEN')
course(dept, course_number)[source]

Return an object of semester-independent course info. All arguments should be strings.

>>> cis120 = r.course('cis', '120')
department(dept)[source]

Return an iterator of all course-info objects in a department, in no particular order.

search(params, validate=False)[source]

Return a generator of section objects for the given search params.

Parameters:
  • params – Dictionary of course search parameters.
  • validate – Optional. Set to true to enable request validation.
>>> cis100s = r.search({'course_id': 'cis', 'course_level_at_or_below': '200'})
search_params()[source]

Return a dictionary of possible search parameters and their possible values and descriptions.

section(dept, course_number, sect_number)[source]

Return a single section object for the given section. All arguments should be strings. Throws a ValueError if the section is not found.

>>> lgst101_bfs = r.course('lgst', '101', '301')

Dining API Wrapper

This documentation explains the methods of the Dining object. For the specific fields on the objects returned by these methods, see the official documentation.

class penn.dining.Dining(bearer, token)[source]

The client for the Registrar. Used to make requests to the API.

Parameters:
  • bearer – The user code for the API
  • token – The password code for the API

Usage:

>>> from penn import Dining
>>> din = Dining('MY_USERNAME_TOKEN', 'MY_PASSWORD_TOKEN')
menu_daily(building_id)[source]

Get a menu object corresponding to the daily menu for the venue with building_id.

Parameters:building_id – A string representing the id of a building, e.g. “abc”.
>>> commons_today = din.menu_daily("593")
menu_weekly(building_id)[source]

Get an array of menu objects corresponding to the weekly menu for the venue with building_id.

Parameters:building_id – A string representing the id of a building, e.g. “abc”.
>>> commons_week = din.menu_weekly("593")
venues()[source]

Get a list of all venue objects.

>>> venues = din.venues()

Directory API Wrapper

This documentation explains the methods of the Directory object. For the specific fields on the objects returned by these methods, see the official documentation.

class penn.directory.Directory(bearer, token)[source]

The client for the Directory. Used to make requests to the API.

Parameters:
  • bearer – The user code for the API
  • token – The password code for the API

Usage:

>>> from penn import Directory
>>> d = Directory('MY_USERNAME_TOKEN', 'MY_PASSWORD_TOKEN')

Get a detailed list of person objects for the given search params.

Parameters:params – Dictionary specifying the query parameters
>>> people_detailed = d.detail_search({'first_name': 'tobias', 'last_name': 'funke'})
person_details(person_id, standardize=False)[source]

Get a detailed person object

Parameters:person_id – String corresponding to the person’s id.
>>> instructor = d.person('jhs878sfd03b38b0d463b16320b5e438')
search(params, standardize=False)[source]

Get a list of person objects for the given search params.

Parameters:
  • params – Dictionary specifying the query parameters
  • standardize – Whether to standardize names and other features, currently disabled for backwards compatibility. Currently standardizes names, lowercases emails, and removes faculty label from affiliation.
>>> people = d.search({'first_name': 'tobias', 'last_name': 'funke'})

Transit API Wrapper

This documentation explains the methods of the Transit object. For the specific fields on the objects returned by these methods, see the official documentation.

class penn.transit.Transit(bearer, token)[source]

The client for Transit. Used to make requests to the API.

Parameters:
  • bearer – The user code for the API
  • token – The password code for the API

Usage:

>>> from penn import Transit
>>> trans = Transit('MY_USERNAME_TOKEN', 'MY_PASSWORD_TOKEN')
apc(start_date, end_date)[source]

Return all APC data packets in date range

Parameters:
  • start_date – The starting date for the query.
  • end_date – The end date for the query.
>>> import datetime
>>> today = datetime.date.today()
>>> trans.apc(today - datetime.timedelta(days=1), today))
configuration()[source]

Return route configuration info

>>> route_config = trans.configuration()
mdt(start_date, end_date)[source]

Return all MDT data packets in date range

Parameters:
  • start_date – The starting date for the query.
  • end_date – The end date for the query.
>>> import datetime
>>> today = datetime.date.today()
>>> trans.mdt(today - datetime.timedelta(days=1), today))
prediction()[source]

Return route data and time predictions

>>> predictions = trans.prediction()
stopinventory()[source]

Return a list all transit stops.

>>> stops = trans.stopinventory()
stoptimes(start_date, end_date)[source]

Return all stop times in the date range

Parameters:
  • start_date – The starting date for the query.
  • end_date – The end date for the query.
>>> import datetime
>>> today = datetime.date.today()
>>> trans.stoptimes(today - datetime.timedelta(days=1), today)
transapc(start_date, end_date)[source]

Return detail of boardings, alightings, by vehicle and stop, including the passenger load leaving the stop (this is only for vehicles equipped with APC hardware)

Parameters:
  • start_date – The starting date for the query.
  • end_date – The end date for the query.
>>> import datetime
>>> today = datetime.date.today()
>>> trans.transapc(today - datetime.timedelta(days=1), today))

Map API Wrapper

This documentation explains the methods of the Map object. For the specific fields on the objects returned by these methods, see the official documentation.

class penn.map.Map(bearer, token)[source]

The client for the Map Search API.

Parameters:
  • bearer – The user code for the API
  • token – The password code for the API

Usage:

>>> from penn import Map
>>> n = Map('MY_USERNAME_TOKEN', 'MY_PASSWORD_TOKEN')
search(keyword)[source]

Return all buildings related to the provided query.

Parameters:keyword – The keyword for your map search
>>> results = n.search('Harrison')

News API Wrapper

This documentation explains the methods of the News object. For the specific fields on the objects returned by these methods, see the official documentation.

class penn.news.News(bearer, token)[source]

The client for the News Search API.

Parameters:
  • bearer – The user code for the API
  • token – The password code for the API

Usage:

>>> from penn import News
>>> n = News('MY_USERNAME_TOKEN', 'MY_PASSWORD_TOKEN')
search(keyword)[source]

Return all news related to the provided query.

Parameters:keyword – The keyword for your news search
>>> results = n.search('interview')

Laundry Website Scraper

This documentation explains the methods of the Laundry object. This SDK module is implemented by scraping the laundry alert service.

class penn.laundry.Laundry[source]

The client for Laundry. Used to make requests to the API.

Usage:

>>> from penn import Laundry
>>> l = Laundry()
all_status()[source]

Return names, hall numbers, and the washers/dryers available for all rooms in the system

>>> all_laundry = l.all_status()
Returns:Mapping from hall name to associated link in SUDS. Creates inverted index from id to hall
hall_status(hall_id)[source]

Return the status of each specific washer/dryer in a particular laundry room.

Parameters:hall_id – Integer corresponding to the id of the hall. This id is returned as part of the all_status call.
>>> english_house = l.hall_status("English%20House")
machine_usage(hall_no)[source]

Returns the average usage of laundry machines every hour for a given hall.

The usages are returned in a dictionary, with the key being the day of the week, and the value being an array listing the usages per hour.

Parameters:hall_no – integer corresponding to the id number for the hall. Thus number is returned as part of the all_status call.
>>> english_house = l.machine_usage(2)

Library Website Scraper

This documentation explains the methods of the StudySpaces object. This SDK module is implemented by scraping the Penn Libraries LibCal website.

class penn.studyspaces.StudySpaces[source]

Used for interacting with the UPenn library GSR booking system.

Usage:

>>> from penn import StudySpaces
>>> s = StudySpaces()
get_buildings()[source]

Returns a list of building IDs, building names, and services.

static get_room_id_name_mapping(building)[source]

Returns a dictionary mapping id to name, thumbnail, and capacity.

get_rooms(building, start, end)[source]

Returns a dictionary matching all rooms given a building id and a date range.

static parse_date(date)[source]

Converts library system dates into timezone aware Python datetime objects.

Penn Academic Calendar API

This documentation explains the methods of the Calendar object.

class penn.calendar3year.Calendar[source]
pull_3year()[source]

Returns a list (in JSON format) containing all the events from the Penn iCal Calendar.

List contains events in chronological order.

Each element of the list is a dictionary, containing:
  • Name of the event ‘name’
  • Start date ‘start’
  • End date ‘end’