🌐
Medium
medium.com › analytics-vidhya › getting-started-with-github-api-dc7057e2834d
Getting Started with Github API. REST API v3 using Python | by Gaganpreet Kaur Kalsi | Analytics Vidhya | Medium
July 20, 2020 - Example JSON → data = {“name” : “Hello-repo”} NOTE : — Be careful while constructing a URL and with the type of request. These were mostly the areas where the API threw an error to me.
🌐
GitHub
github.com › PyGithub › PyGithub
GitHub - PyGithub/PyGithub: Typed interactions with the GitHub API v3 · GitHub
... from github import Github # ... g = Github(auth=auth) # Github Enterprise with custom hostname g = Github(base_url="https://{hostname}/api/v3", auth=auth) # Then play with your Github objects: for repo in g.get_user().g...
Starred by 7.7K users
Forked by 1.9K users
Languages   Python 99.6% | Shell 0.4%
Discussions

oauth 2.0 - how to use github api token in python for requesting - Stack Overflow
I'm able to obtain Github api token in python using username and password but i'm not able to use that API-Token for requesting any POST/DELETE/PATCH. How do we use Github API-Tokens for making any More on stackoverflow.com
🌐 stackoverflow.com
How to use FIX api with python?
Yes I found a good example from FTX on github https://github.com/ftexchange/ftx/tree/master/fix More on reddit.com
🌐 r/algotrading
5
3
August 31, 2020
Ring API info

This information needs to be used for integrating into HomeKit using r/homebridge.

More on reddit.com
🌐 r/ringdoorbell
17
19
November 23, 2017
Where to start with learning how to use API's?
And if you have a suggestion as to an easier API I could learn to use as my first one then that would be awesome too! Google Maps API is very easy. I recommend starting with the with the distance calculator web service API , then try experimenting with some of the JavaScript and Android APIs if you're feeling adventurous. More on reddit.com
🌐 r/learnprogramming
62
397
October 12, 2016
🌐
GitHub
github.com › bullhorn › rest-api-example-python
GitHub - bullhorn/rest-api-example-python: A sample Python Web application that demonstrates a very simple usage of the Bullhorn REST API
This a sample Python application that demonstrates a very simple usage of the Bullhorn REST API from a Web application. The biggest initial hurdle for developers is typically getting OAuth authentication working properly, so much of this sample ...
Starred by 29 users
Forked by 19 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › akbarahmed › basic-python-rest-api
GitHub - akbarahmed/basic-python-rest-api: Example of how to create a basic REST API in Python
Example of how to create a basic REST API in Python - akbarahmed/basic-python-rest-api
Forked by 9 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › messagebird › python-rest-api
GitHub - messagebird/python-rest-api: This repository contains the open source Python client for MessageBird's REST API.
Please see the other examples for a complete overview of all the available API calls. ... $ python ./examples/voice_create_webhook.py --accessKey accessKeyWhichNotExist --url https://example.com --title HELLO_WEBHOOK --token HELLO_TOKEN · Complete documentation, instructions, and examples are available at: https://developers.messagebird.com/. The MessageBird REST Client for Python is licensed under The BSD 2-Clause License.
Starred by 71 users
Forked by 64 users
Languages   Python 100.0% | Python 100.0%
🌐
TechGeekBuzz
techgeekbuzz.com › blog › how-to-use-github-api-in-python
How to Use GitHub API in Python? [A Step by Step Guide]
With GitHub HTTP REST APIs we can access the public data or information using the Python requests library. To use the GitHub HTTPs REST APIs, we can send the GET request to the URL https://api.github.com/ .
🌐
GitHub
github.com › miguelgrinberg › REST-tutorial
GitHub - miguelgrinberg/REST-tutorial: Files for my REST API tutorials featuring a server written in Python and a web client written in Javascript. · GitHub
Files for my REST API tutorials featuring a server written in Python and a web client written in Javascript. - miguelgrinberg/REST-tutorial
Starred by 657 users
Forked by 261 users
Languages   HTML 63.6% | Python 35.8%
🌐
GitHub
github.com › mransbro › python-api
GitHub - mransbro/python-api: A super simple RESTful api created using Flask. The idea is to have a simple api that can be used with pipeline demos and proof of concepts.
A super simple RESTful api created using Flask. The idea is to have a simple api that can be used with pipeline demos and proof of concepts. - mransbro/python-api
Starred by 6 users
Forked by 56 users
Languages   Python 79.4% | Dockerfile 20.6% | Python 79.4% | Dockerfile 20.6%
Find elsewhere
🌐
GitHub
github.com › nanotaboada › python-samples-fastapi-restful
GitHub - nanotaboada/python-samples-fastapi-restful: 🧪 Proof of Concept for a RESTful API built with Python 3 and FastAPI
1 week ago - 🧪 Proof of Concept for a RESTful API built with Python 3 and FastAPI - nanotaboada/python-samples-fastapi-restful
Starred by 126 users
Forked by 22 users
Languages   Python 92.0% | Dockerfile 5.7% | Shell 1.7% | JavaScript 0.6%
🌐
The Python Code
thepythoncode.com › article › using-github-api-in-python
How to Use Github API in Python - The Python Code
Using Github Application Programming Interface v3 to search for repositories, users, making a commit, deleting a file, and more in Python using requests and PyGithub libraries.
🌐
GitHub
github.com › ynsrc › python-simple-rest-api
GitHub - ynsrc/python-simple-rest-api: Simple REST API Example with pure Python · GitHub
... Default port is 5000, you can change it in server.py. $ curl "http://127.0.0.1:5000/" { "name": "Python REST API Example", "summary": "This is simple REST API architecture with pure Python", "actions": [ "add", "delete", "list", "search" ], "version": "1.0.0" }...
Starred by 2 users
Forked by 6 users
Languages   Python
🌐
GitHub
github.com › optimizely › fs_rest_customer
GitHub - optimizely/fs_rest_customer: Example python scripts that use the REST API for FS objects
Example python scripts that use the REST API for FS objects - optimizely/fs_rest_customer
Forked by 2 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › tecladocode › rest-apis-flask-python
GitHub - tecladocode/rest-apis-flask-python: Projects and e-book for our course, REST APIs with Flask and Python
This section (only available on Udemy) helps programmers who are new to Python get acquainted with the language. It is not a complete-beginner Python course! The code in this section includes a simple Flask app that accepts and returns JSON data. Introduction to Docker to run your REST APIs.
Starred by 1.5K users
Forked by 1.5K users
Languages   Python 98.6% | Python 98.6%
🌐
Apify
blog.apify.com › python-github-api
How to use the GitHub API in Python
July 30, 2024 - To perform other Python API operations using the POST, PATCH, or DELETE request, you need the access token. Let's create a new repository using the POST request. In the code below, you pass your access token, repo name, and repo description, ...
🌐
GitHub
github.com › PacktPublishing › Building-REST-APIs-with-Python
GitHub - PacktPublishing/Building-REST-APIs-with-Python: Code repository for Building REST APIs with Python, Published By Packt
This is the code repository for Building REST APIs with Python [Video], published by Packt.
Starred by 16 users
Forked by 13 users
Languages   Python 95.6% | HTML 3.0% | CSS 1.4% | Python 95.6% | HTML 3.0% | CSS 1.4%
Top answer
1 of 5
51

Here's some code that might help you out.

Examples:

Example 1 (auth):

username = 'user'
token = 'token'

login = requests.get('https://api.github.com/search/repositories?q=github+api', auth=(username,token))

Example 2 (headers):

headers = {'Authorization': 'token ' + token}

login = requests.get('https://api.github.com/user', headers=headers)
print(login.json())

Example 3 (delete repo):

user = 'username'
repo = 'some_repo' # Delete this repo

headers = {'Authorization': 'token ' + token}

login = requests.delete('https://api.github.com/' + 'repos/' + user + '/' + repo, headers=headers)

Example 4 (create repo):

repo = 'some_repo'
description = 'Created with api'

payload = {'name': repo, 'description': description, 'auto_init': 'true'}

login = requests.post('https://api.github.com/' + 'user/repos', auth=(user,token), data=json.dumps(payload))

You might want to take a look at the following docs:

Requests Docs

Github API docs

I hope this helps.

2 of 5
39

For one, I would recommend using a wrapper for the API. You're asking a lot of questions on here that could be simplified by finding a wrapper whose API you appreciate. There's a list of wrappers written in Python here.

As for your actually answering your question, the GitHub documentation is fairly clear that you need to send the Authorization header. Your call would actually look like this:

self.headers = {'Authorization': 'token %s' % self.api_token}
r = requests.post(url, headers=self.headers)

Since it seems like you're using requests and a class, might I be so bold as to make a recommendation? Let's say you're doing something like making a client for the API. You might have a class like so:

class GitHub(object):
    def __init__(self, **config_options):
        self.__dict__.update(**config_options)
        self.session = requests.Session()
        if hasattr(self, 'api_token'):
           self.session.headers['Authorization'] = 'token %s' % self.api_token
        elif hasattr(self, 'username') and hasattr(self, 'password'):
           self.session.auth = (self.username, self.password)

    def call_to_the_api(self, *args):
        # do stuff with args
        return self.session.post(url)

The Session object will take care of the authentication for you (either by the tokens or username and password combination).

Also, if you end up deciding to use github3.py for your API wrapper needs, there's a tag on here for it.

🌐
Martin Heinz
martinheinz.dev › blog › 25
All the Things You Can Do With GitHub API and Python | Martin Heinz | Personal Website & Blog
June 15, 2020 - The example text above includes, code snippet, italics and *bold* text and that's exactly what we get back in form of HTML: ... You know these nice green check marks, yellow circles and ugly red crosses next to your commits that are added by CI tools? Do you want to change them (maybe just for fun, maybe as part of your own CI solution)? Of course you do. And there is API for that: g = Github(token) repo = g.get_repo("MartinHeinz/python-project-blueprint") branch = repo.get_branch(branch="master") status = repo.get_commit(sha=branch.commit.sha).create_status( state="success", target_url="https://some-ci-url.com", description="CI in Progress", context="Just testing..."
🌐
GitHub
github.com › topics › python-rest-api
python-rest-api · GitHub Topics · GitHub
March 27, 2022 - django-rest-framework chat-application python-chat-application python-rest-api django-chat-app chat-application-in-django
🌐
Readthedocs
github3.readthedocs.io
github3.py: A Library for Using GitHub’s REST API — github3.py 4.0.1 documentation
github3.py: A Library for Using GitHub’s REST API ... Release v4.0.1. github3.py is wrapper for the GitHub API written in python. The design of github3.py is centered around having a logical organization of the methods needed to interact with the API. As an example, let’s get information ...
🌐
GitHub
github.com › tomimick › restpie3
GitHub - tomimick/restpie3: Python3 REST API server starter kit · GitHub
With dynamic languages such as Python or Javascript or Ruby, tests are even more important than with compiled languages. For locally run tests I expose a method /apitest/dbtruncate in api_dev.py that truncates the data in the database tables before running the API tests. If you like to write tests in a different way, just remove it. ... docker exec -it restpie-dev bash -l -c 'python /app/test/test_api.py' docker exec -it restpie-dev bash -l -c 'python /app/test/test_redis.py'
Starred by 89 users
Forked by 34 users
Languages   Python 87.3% | HTML 7.3% | Dockerfile 3.3% | Shell 2.1%