Skip to content

uclapi/uclapyi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A python client library for UCL API

What this does is allows easier access to the UCL API, without having to manually deal with HTTP requests yourself. This makes start-up time for developing applications quicker meaning hackathon and prototype projects can be constructed quickly. To install this you can do:

pip install -e git+git://github.com/uclapi/uclapyi@master#egg=uclapyi

But how do i use it?

Using this package is designed to be simple. The first step is to initialise a client. You can do this by first importing it:

from uclapyi.uclapyi import Client

You can then initialise it:

client = Client(token="YOUR-TOKEN-HERE")

Now we can make requests by accessing endpoints like functions. For example to get bookings for a room with id 443 and site_id 086 we would do:

bookings = client.roombookings.bookings(roomid="433",siteid="086",results_per_page=10)

All pagination is handled for you as a generator and supports indexing. This allows you to do things like:

for booking in bookings:
  print(booking.contact)
  print(booking.get_room().capacity)
  for equipment in booking.get_equipment():
    print(equipment.description)

This prints out who booked the room, what the capacity is and the equipment available for each booking in the result of the query. This shows the power of a native client library and how much easier it is to use than raw requests.

Is there an dis-advantage of this over raw HTTP requests?

This is a good question and yes there is. Since this wrapper makes everything into an object there is a time cost to converting the data into this form. For example when you get bookings we give you a list of Booking objects, which you can query to get the Room object associated with it. This is apposed to just a dictionary of strings and such that the normal endpoint would return in JSON format.

Limitations holding us back

You might wonder. Whats stopping us from linking everything like Bookings and Rooms. For example can we link desktops and rooms? This shows a problem with inconsistency in UCL data. For example:

desktops = client.resources.desktops()
desktop = desktops[0]
room = client.roombookings.rooms(sitename=desktop.building_name)
print(desktop.roomname)
for r in room:
  if "Public Cluster" in r.roomname:
    print(r.roomname)

This gives us the output:

Basement-B115A
Cruciform Building B1.15A - Public Cluster

This shows that the room name in the desktop database and the bookings database is unfortunately not the same.

About

A python wrapper library for UCL API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages