Skip to main content

A Python tool to interact with GitHub Gists

Project description

Gist Python Tool

This Python tool allows you to interact with GitHub Gists. You can create, read, list, and delete gists using this tool.

Prerequisites

  • Python 3.12
  • GitHub personal access token

Installation

1. Clone the Repository

git clone <repository-url>
cd <repository-directory>

2. Create and Activate a Virtual Environment

python3.12 -m venv .venv
source .venv/bin/activate  # On Windows use `.venv\Scripts\activate`

3. Install Dependencies

Install the required dependencies using pip and the requirements.txt file:

pip install -r requirements.txt

Configuration

Set Up Authentication

You need to create a GitHub personal access token and save it in a file named ~/.gist. This token will be used to authenticate your requests to the GitHub API.

  1. Go to GitHub Personal Access Tokens.
  2. Generate a new token with the gist scope.
  3. Save the token in a file named ~/.gist in your home directory:
echo "your_personal_access_token" > ~/.gist

Usage

1. Creating a Gist

You can create a gist with the following sample code:

from src.gist import Gist

# Sample content for creating a gist
content = "print('Hello, World!')"
options = {
    'description': 'A hello world program',
    'public': True,
    'filename': 'hello.py'
}

result = Gist.gist(content, options)
print("Gist created:", result)

2. Listing All Gists

List all gists for the authenticated user:

from src.gist import Gist

gists = Gist.list_all_gists()
print("Listing all gists:", gists)

3. Reading a Gist

Read the content of a specific gist by its ID:

from src.gist import Gist

gist_id = 'your_gist_id_here'
content = Gist.read_gist(gist_id)
print("Gist content:", content)

4. Deleting a Gist

Delete a specific gist by its ID:

from src.gist import Gist

gist_id = 'your_gist_id_here'
Gist.delete_gist(gist_id)
print("Gist deleted successfully.")

Running Tests

To run the tests, ensure you have pytest installed and configured. You can run the tests using the following command:

pytest

Make sure your PYTHONPATH includes the src directory. You can set it in your pyproject.toml file:

[tool.pytest.ini_options.env]
PYTHONPATH = "src"

Project Structure

your_project/
│
├── src/
│   └── gist.py
│
├── tests/
│   └── test_gist.py
│
├── requirements.txt
├── pyproject.toml
└── README.md

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Author

Farshid Ashouri

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

pygister-0.1.1.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

pygister-0.1.1-py3-none-any.whl (3.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page