Im new to Python, and im building a wrapper for an api. I would want to let the user decide if he/she wants to use a decorator on methods I expose from my module.
For example:
# create a new instance
api = MyApi()
# return a simple json response with all the data related to a timetable
print api.time_table
Now the user has all the data, and can do whatever he/she wants. I would want to add some kind of 'convenience' methods, for example; to let the user get a small part of the json instead of the whole big json response.
My idea was to use pythons decorators for this. Optionally my goal whould be something like this:
# use the method and get al the data
print api.time_table
# Optionally, get a specific part, just the shows part. (PSEUDO CODE BELOW)
@shows
print api.time_table
Naturally, thats not how decorators work, but is there a way to optionally use a decorator on a existing class method, or does the decorator always have to be wrapping the original method?
So what is the most Pythonic way here? I really would like to use decorator, but if thats a bad idea here, im fine with just creating more 'convenience' methods inside my Api
class.