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'})
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')
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")
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")
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')
-
detail_search
(params, standardize=False)[source]¶ 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))
-
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))
-
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.
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.
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()
-
create_hall_to_link_mapping
()[source]¶ 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()
-
static
get_room_id_name_mapping
(building)[source]¶ Returns a dictionary mapping id to name, thumbnail, and capacity.
-
static