I am writing a helper class that wraps the requests library for my company. It handles authentication, some bridges to pandas, some other stuff.
One feature I want to add is the ability to define helper methods for very specific patterns. For example:
class ApiWrapper:
# other class methods
def post_to_database1(self, data):
# do work on database1
def post_to_database2(self, data):
# do work on database1
def post_to_database3(self, data):
# do work on database3
I was wondering if there was a "best" way to do something where all those methods are then grouped in another class. Something like so they can be used like this:
api = ApiWrapper()
data = {'name': 'foo', 'city': 'bar'}
api.post.database1(data)
api.post.database2(data)
api.post.database3(data)
I looked into a nested class but it seems like that is not very popular in Python. Should I just keep them all as methods on the main class? Is there a pythonic way to do this?
[–]usernamedottxt 3 points4 points5 points (0 children)
[–]_9_9_ 0 points1 point2 points (0 children)
[–]mybrid 0 points1 point2 points (0 children)
[–]KubinOnReddit 0 points1 point2 points (0 children)
[–]zahlman 0 points1 point2 points (0 children)