I'm new-ish to Python. I spend a fair of time working with the Azure Python SDK's. There is a pattern in these SDK's that works well for me. I want to duplicate the pattern below using the GitHub REST API, but can't find a GitHub "Service Client" or the like in the API docs.
There is an idea of RestClient
in the docs, but its server code, not REST API syntax.
How do I create a service client one time, then use it for multiple REST calls?
Example Azure Python SDK pattern:
Create a client to interact with a specific service
- Feed the
connection string
,api key
,credential
, etc. one time
- Feed the
Pass the client to other functions throughout the program
from azure.data.tables import TableClient
def create_table_service(conn_string, table_name):
try:
table_service = TableClient.from_connection_string(conn_string, table_name)
except Exception as e:
logging.error(f'##### Error creating Table Service Client: {e}')
return table_service
def update_feed_states(table_client, table_name, entity):
try:
test = table_client.insert_or_replace_entity(table_name, entity)
return test
except Exception as e:
logging.error(f'##### Could not insert or update in : {table_name}: {e}')
raise e
#----------------------------------------------
conn_string = '<connection-string-here>'
table_name = '<table-name-here>'
entity = {
'PartitionKey': 'foo',
'RowKey': 'bar',
'last_mod': '10/22/22'
}
#------------------------------------------------------
table_client = create_table_service(conn_string, table_name)
table_updates = update_feed_states(table_client, table_name, entity)