with Tutorials if you’re new (but they don’t always have this) • API endpoints are listed under Resources There’s an API for that! @mariatta PyCon Colombia 2022
with Tutorials if you’re new (but they don’t always have this) • API endpoints are listed under Resources There’s an API for that! @mariatta PyCon Colombia 2022
secret! • Don’t store as plain text • Don’t commit to your codebase • Use environment variables There’s an API for that! @mariatta PyCon Colombia 2022 # DON'T DO THIS TOKEN = "my token" # DO THIS import os TOKEN = os.environ["TOKEN"]
APIs • Also called toolkit or SDKs or wrappers • Abstraction and simpli f ication. • Hides details of request authorization, headers, signature veri f ication • Write code in your favourite language (e.g. Python) • No client library? Write one! • Use Swagger client if they have OpenAPI There’s an API for that! @mariatta PyCon Colombia 2022
framework, Flask, FastAPI, aiohttp, etc. • Always verify incoming requests • Sometimes they use secrets • Sometimes they’d pass speci f ic header • The client library should provide this. If not, f ile a feature request! There’s an API for that! @mariatta PyCon Colombia 2022
access token or OAuth2 • O ff icial Client Libraries: in Ruby, .NET, JavaScript • Third party Python library: https://gidgethub.readthedocs.io/ • My GitHub App tutorial: https://github-app-tutorial.readthedocs.io/ There’s an API for that! @mariatta PyCon Colombia 2022 > python3 -m pip install gidgethub
credentials=creds) result = ( service.spreadsheets() .values() .get(spreadsheetId=SPREADSHEET_ID, range=SHEET_RANGE) .execute() ) values = result.get("values", []) for row in values: print(row) API for reading rows from Google Sheets There’s an API for that! @mariatta PyCon Colombia 2022
credentials=creds) requests = { "createSlide": { "objectId": "slide_page_1", "slideLayoutReference": {"predefinedLayout": "TITLE_AND_BODY"}, } } body = {"requests": requests} response = ( service.presentations() .batchUpdate(presentationId=PRESENTATION_ID, body=body) .execute() ) API for adding a slide on Google Slides There’s an API for that! @mariatta PyCon Colombia 2022
APIs samples", }, }, { "insertText": {"objectId": page_body["objectId"], "text": "Visit the docs at https://developers.google.com/", }, }, ] request_body = {"requests": requests} response = ( service.presentations() .batchUpdate(presentationId=PRESENTATION_ID, body=request_body) .execute() ) API for adding texts to a page on Google Slides There’s an API for that! @mariatta PyCon Colombia 2022
SDKs: Python, Node, and Java • Docs and Tutorials: https://slack.dev/python-slack-sdk/ There’s an API for that! @mariatta PyCon Colombia 2022 > python3 -m pip install slack_sdk
= client.chat_postMessage( channel="general", text="¡Hola, PyCon Colombia!" ) API for posting a message in a channel There’s an API for that! @mariatta PyCon Colombia 2022
key • No Python client library :( • Use requests or HTTPX • Maybe you should write one :) There’s an API for that! @mariatta PyCon Colombia 2022 (beta)
key • No o ff icial Python client library, but they have OpenAPI specs • Swagger SDK client: https://github.com/musixmatch/musixmatch-sdk • Third party Python wrapper: pymusixmatch There’s an API for that! @mariatta PyCon Colombia 2022 > python3 -m pip install pymusixmatch
Shares events posted on GitHub to Slack channel • Repo: https://github.com/pyladies/pyladies-bot There’s an API for that! @mariatta PyCon Colombia 2022