0

When working with APIs, we have the one API-object:

class API:
  def __init__(self, sub=None):
    self.sub = sub
  def get_api(self, name):
    return build(name, sub=self.sub) #custom

All api-calls we want to support are added as class-funtions along with the exception-handling.

  def event_delete(self, *args, **kwargs):
    return query_backoff(self.get_api("calendar").events().delete(*args, **kwargs))
  def student_list(self, *args, **kwargs):
    reutrn query_backoff(self.get_api("classroom").courses().students().list(*args, **kwargs))
  def member_get(self, *args, **kwargs):
    try:
      return query_backoff(self.get_api("admin_directory").members().get(*args, **kwargs))
    except ...

This file has grown to thousands of lines of python-code. I want to split it into multiple files. I don't know how to do this, as they are class-functions.

Niklas Ternvall
  • 510
  • 1
  • 3
  • 19
  • Build rest directory structure, then build classes - one per each level... Or at list that is what I usually do. :) – Michał Zaborowski Nov 21 '16 at 13:54
  • You can take a look at python mixin classes. This [so question](http://stackoverflow.com/questions/533631/what-is-a-mixin-and-why-are-they-useful) describes it well – algrebe Nov 21 '16 at 13:55

0 Answers0