A Python Module to create and access GitHub Gists
Project description
PythonGists is a Python 2/3 module to create, view and access data from GitHub Gists. It uses requests and oauth to function and is based on the GitHub v3 API.
Why PythonGists?
There are numerous Python modules available for the GitHub v3 API but PythonGists is different. For starters, it is aimed only at the Gists part of the GitHub API and not the entire API. And it will never feature non Gists part of the GitHub API.
So you might be thinking that you could have used python3-github or any other module for Gists. Technically, you could but PythonGistss is more specific. In Systems where saving even a tiny amount of space matters (like your VPS), PythonGistss will take less space and do the same (provided you only want GitHub Gists Access).
Note
This module is not to be confused with PyGist which is just a CLI. This is a python module (actually I would have picked up a different name if I knew about that module)
Installation
Installation is done through PIP:
pip install PythonGists
Usage
You can use PythonGists either by signing into GitHub or anonymously. Note that the syntax for logged in usage and anonymous usage is different. Here are some demos:
Create Gist Anonymously
from PythonGists import PythonGists
link = PythonGists.Gist(description='a sample gist',content='Hey GitHub',name='demo.txt')
print("The link is {0}".format(link))
Create Gist as a logged in user
from PythonGists import PythonGists
gistObject=PythonGists(username='youruser',password='somepass')
print(gistObject.createGist(description='a sample gist',content='Hey GitHub',name='demo.txt'))
'This will print the link'
Create Gist from File Anonymously
from PythonGists import PythonGists
link = PythonGists.GistFromFile(description='a sample gist',file='demo.py')
print("The link is {0}".format(link))
Create Gist from File (logged in)
from PythonGists import PythonGists
gistObject=PythonGists(username='youruser',password='somepass')
print(gistObject.createGistFromFile(description='a sample gist',file='demo.py'))
'This will print the link'
Get User Gists Links (same for both)
Here just replace GitHubGist in the print line with your gistObject for logged in users.
from PythonGists import PythonGists
print(PythonGists.getGistsLinks('geekpradd'))
Get User Gists Data (same for both)
Here just replace GitHubGist in the print line with your gistObject for logged in users.
from PythonGists import PythonGists
gistArray = PythonGists.getGistsData('geekpradd')
Note that gistArray will contain objects of the Gist Class which has access to the Gist data. Now, I’ll show you how to access Gist data from the Gist Object.
Get Single Gist Data
python from PythonGists import Gist gistObj = Gist('https://gist.github.com/geekpradd/a3e7a590887cf7bbf161') print (gistObj.getFileContent()) #Will retutn a Dictionary with keys = File names and values = file content
About
This module is created by Pradipta (geekpradd) using the GitHub API and requests.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file PythonGists-1.1.3.tar.gz
.
File metadata
- Download URL: PythonGists-1.1.3.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9e4e087ef9286d7b648fceab2c004502e3ea7edb9deec5328f8a73934554bd8 |
|
MD5 | cfd0a8f61f35a2b753e70d50154235f0 |
|
BLAKE2b-256 | b149e2f51f644adfe74f99b26da843c98c2e68b46aee1f45282e86ee98a801f2 |