DEV Community

Cover image for A Python Script to connect to GitHub and Fetches Search Results
Ajeet Singh Raina
Ajeet Singh Raina

Posted on

9

A Python Script to connect to GitHub and Fetches Search Results

The GitHub API is a RESTful API for interacting with the GitHub platform. It allows developers to programmatically access various aspects of the platform, such as managing repositories, managing users, and managing issues.

The API supports a variety of methods for creating, retrieving, updating, and deleting resources, making it a powerful tool for automating various tasks and integrating with other systems. The API requires authentication for all methods except for those that are publicly accessible. The authentication can be done using a personal access token, OAuth2, or with basic authentication. GitHub provides extensive documentation for its API, making it easy to get started and use.

Additionally, there are many client libraries available in different programming languages, which makes it easier to integrate with the API and reduces the amount of code you need to write.

Here is a sample Python script that fetches search results from GitHub. Please note that you will require Personal Account Token to get it working:

import requests
import json

url = "https://api.github.com/search/repositories?q=docker+desktop+extension&sort=stars&order=desc"

headers = {
    "Authorization": "github_pat_XXXX"
}

response = requests.get(url, headers=headers)

if response.status_code == 200:
    data = json.loads(response.text)
    for repository in data["items"]:
        print(f"{repository['name']}: {repository['html_url']}")
else:
    print("Could not retrieve data from GitHub.")
Enter fullscreen mode Exit fullscreen mode

In this script, you'll need to replace with your actual GitHub personal access token. The token is passed in the request headers as an Authorization header. This allows the script to access protected resources in your GitHub account, such as searching for repositories.

The link to each repository is fetched and added to the output along with the repository name, separated by a colon (:).

python3 new.py 
docker-php-extension-installer: https://github.com/mlocati/docker-php-extension-installer
codechecker: https://github.com/Ericsson/codechecker
SingleFileZ: https://github.com/gildas-lormeau/SingleFileZ
china-dictatorship: https://github.com/cirosantilli/china-dictatorship
vscode-docker: https://github.com/microsoft/vscode-docker
flask-bones: https://github.com/cburmeister/flask-bones
ProjectFib: https://github.com/anantdgoel/ProjectFib
S3Mock: https://github.com/adobe/S3Mock
home: https://github.com/gege-circle/home
docker-php: https://github.com/chialab/docker-php
dockbix-xxl: https://github.com/monitoringartist/dockbix-xxl
wind-layer: https://github.com/sakitam-fdd/wind-layer
powerstrip: https://github.com/ClusterHQ/powerstrip
selenium-jupiter: https://github.com/bonigarcia/selenium-jupiter
gnome-shell-extension-docker: https://github.com/gpouilloux/gnome-shell-extension-docker
hacktoberfest-2022: https://github.com/docker/hacktoberfest-2022
azure-docker-extension: https://github.com/Azure/azure-docker-extension
pgrocks-fdw: https://github.com/vidardb/pgrocks-fdw
docker-php-yii2: https://github.com/dmstr/docker-php-yii2
docker-community-extensions: https://github.com/collabnix/docker-community-extensions
alpine-php-fpm: https://github.com/joseluisq/alpine-php-fpm
autoview-tradingview-chrome-docker-bot: https://github.com/IAMtheIAM/autoview-tradingview-chrome-docker-bot
.config: https://github.com/zszszszsz/.config
docker-phpfpm: https://github.com/adhocore/docker-phpfpm
coc-docker: https://github.com/josa42/coc-docker
china-dictatorhsip-6: https://github.com/cirosantilli/china-dictatorhsip-6
testcontainers-spock: https://github.com/testcontainers/testcontainers-spock
Dockery: https://github.com/oslabs-beta/Dockery
docker-extension: https://github.com/tailscale/docker-extension
volumes-backup-extension: https://github.com/docker/volumes-backup-extension
ajeetraina@Docker-Ajeet-Singh-Rainas-MacBook-Pro chatgpt % vi new.py 
ajeetraina@Docker-Ajeet-Singh-Rainas-MacBook-Pro chatgpt % python3 new.py
.config: https://github.com/zszszszsz/.config
Dockery: https://github.com/oslabs-beta/Dockery
docker-extension: https://github.com/tailscale/docker-extension
ransomware: https://github.com/abhir98/ransomware
jfrog-docker-desktop-extension: https://github.com/jfrog/jfrog-docker-desktop-extension
dd-extension-lgtm: https://github.com/cedricziel/dd-extension-lgtm
openshift-dd-ext: https://github.com/redhat-developer/openshift-dd-ext
k9s-dd-extension: https://github.com/spurin/k9s-dd-extension
pgadmin4-docker-extension: https://github.com/marcelo-ochoa/pgadmin4-docker-extension
trivy-docker-extension: https://github.com/aquasecurity/trivy-docker-extension
drone-ci-docker-extension: https://github.com/harness/drone-ci-docker-extension
docker-extension: https://github.com/loopDelicious/docker-extension
swagger-editor-docker-extension: https://github.com/n-murphy/swagger-editor-docker-extension
wasm-docker-extension: https://github.com/cmrigney/wasm-docker-extension
microcks-docker-desktop-extension: https://github.com/microcks/microcks-docker-desktop-extension
docker-extension-golang-playground: https://github.com/rumpl/docker-extension-golang-playground
diveintoansible-extension: https://github.com/spurin/diveintoansible-extension
docker-desktop-extension: https://github.com/okteto/docker-desktop-extension
docker-extension-rabbitmq: https://github.com/Yogendra0Sharma/docker-extension-rabbitmq
docker-storj-extension: https://github.com/elek/docker-storj-extension
github-registry-docker-desktop-extension: https://github.com/peacecwz/github-registry-docker-desktop-extension
docker-desktop-extension-issues: https://github.com/mutagen-io/docker-desktop-extension-issues
sdw-docker-extension: https://github.com/marcelo-ochoa/sdw-docker-extension
vcluster-dd-extension: https://github.com/loft-sh/vcluster-dd-extension
extension-docker-desktop: https://github.com/epinio/extension-docker-desktop
asyncapi-studio-docker-extension: https://github.com/thiyagu06/asyncapi-studio-docker-extension
gefyra-docker-desktop-extension: https://github.com/gefyrahq/gefyra-docker-desktop-extension
oraclexe-docker-extension: https://github.com/marcelo-ochoa/oraclexe-docker-extension
docker-extensions-101: https://github.com/collabnix/docker-extensions-101
step-ca-docker-extension: https://github.com/hslatman/step-ca-docker-extension
Enter fullscreen mode Exit fullscreen mode

Jetbrains image

Don’t Become a Data Breach Headline

57% of organizations have suffered from a security incident related to DevOps toolchain exposures. Is your CI/CD protected? Check out these nine practical tips to keep your CI/CD secure—without adding friction.

Learn more

Top comments (0)

Image of Quadratic

Free AI chart generator

Upload data, describe your vision, and get Python-powered, AI-generated charts instantly.

Try Quadratic free

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay