Skip to main content

Enhanced Python GitHub client.

Project description

PyPI version Python Development Status Maintenance PyPI License


Python GitHub Plus

An enhanced Python client for GitHub that extends the functionality of the official pygithub package, providing better error handling, merge request management, branch operations, and more.


Features

  • ✅ Simplified connection to GitHub instances
  • ✅ Robust error handling with comprehensive logging
  • Service-based architecture for organized functionality
  • Project management (members, info, etc.)
  • Branch operations (create, delete, protect, list, etc.)
  • Pull Request management (create, merge, approve, assign, comment, etc.)
  • Workflow operations (trigger, monitor, wait for completion, etc.)
  • Tag management (create, delete, list, etc.)
  • File operations (read, create, update, delete, etc.)

Installation

pip install python-github-plus

Configuration

The package uses environment variables for authentication and configuration:

# Required environment variables
GitHub_ACCESS_TOKEN=your_github_access_token
GitHub_URL=https://github.com  # Your GitHub instance URL (default: github.com)

Examples

Basic Setup and Connection

from python_github_plus import GitHubClient

# Initialize GitLab client with service-based architecture
github_client = GitHubClient(
    access_token="your_access_token",  # Note: parameter name changed
    repo_full_name="your-repo-owner/your-repo-name",
)

# Access different services
project_service = github_client.project
branch_service = github_client.branch
pr_service = github_client.pull_request
workflows_service = github_client.workflows
tag_service = github_client.tag
file_service = github_client.file

Branch Management

from python_github_plus import GitHubClient

github_client = GitHubClient(
    access_token="your_access_token",  # Note: parameter name changed
    repo_full_name="your-repo-owner/your-repo-name",
)

# Create a new branch
branch = github_client.branch.create(
    branch_name="feature/new-feature",
    from_branch="main"
)
print(f"Created branch: {branch.ref}")

# List branches
branches = github_client.branch.list()
for branch in branches:
    print(f"Branch: {branch.name}")

# Protect a branch
github_client.branch.protect("main")

# Delete a branch
github_client.branch.delete("feature/old-feature")

Pull Request Management

from python_github_plus import GitHubClient

github_client = GitHubClient(
    access_token="your_access_token",  # Note: parameter name changed
    repo_full_name="your-repo-owner/your-repo-name",
)

# Create a pull request
pr = github_client.pull_request.create(
    title="Add new feature",
    from_branch="feature/new-feature",
    target="main"
)
print(f"Created PR: !{pr.number}")

# Assign PR to a user
github_client.pull_request.assign(pr.number, "username")

# Add a comment
github_client.pull_request.add_comment(pr.number, "Great work!")

# Approve the PR
github_client.pull_request.approve(pr.number)

# Merge the PR
github_client.pull_request.merge(pr.number)

Workflow Operations

import time
from python_github_plus import GitHubClient

github_client = GitHubClient(
    access_token="your_access_token",  # Note: parameter name changed
    repo_full_name="your-repo-owner/your-repo-name",
)

# Trigger a workflows
workflows = github_client.workflow.trigger(
    workflow_name="CI",
    branch_name="main",
)
print(f"Workflow triggered: {workflows.id}")

time.sleep(5)  # wait a bit for the workflow to register
run_id = github_client.workflow.last_run_by_id(workflow_id=workflows.id)

# Check workflow run status
status = github_client.workflow.status(run_id=run_id.id)
print(f"Workflow run status: {status}")

# Wait for workflows completion
final_status = github_client.workflow.wait_until_finished(
    run_id=run_id.id,
    check_interval=30,
    timeout=3600
)
print(f"Workflow run completed with status: {final_status}")

File Operations

from python_github_plus import GitHubClient

github_client = GitHubClient(
    access_token="your_access_token",  # Note: parameter name changed
    repo_full_name="your-repo-owner/your-repo-name",
)

# Read file content
file_content = github_client.file.fetch_content(
    file_path="README.md",
    ref="main"
)
print(f"File content: {file_content[:100]}...")

Tag Management

from python_github_plus import GitHubClient

github_client = GitHubClient(
    access_token="your_access_token",  # Note: parameter name changed
    repo_full_name="your-repo-owner/your-repo-name",
)

# Create a tag
tag = github_client.tag.create(
    tag_name="v1.0.0",
    from_branch="main",
    message="Release version 1.0.0"
)
print(f"Created tag: {tag.name}")

# List tags
tags = github_client.tag.list()
for tag in tags:
    print(f"Tag: {tag.name}")

# Delete a tag
github_client.tag.delete("v0.9.0")

Project Management

from python_github_plus import GitHubClient

github_client = GitHubClient(
    access_token="your_access_token",  # Note: parameter name changed
    repo_full_name="your-repo-owner/your-repo-name",
)

# Get project information
project_info = github_client.project.get_info()
print(f"Project: {project_info.name}")
print(f"Description: {project_info.description}")

# List project members
members = github_client.project.list_members()
for member in members:
    print(f"Member: {member.username}")

# Add a member
github_client.project.add_member("newuser", 30)  # 30 = Developer access level

# Remove a member
github_client.project.remove_member("olduser")

🤝 Contributing

If you have a helpful tool, pattern, or improvement to suggest: Fork the repo
Create a new branch
Submit a pull request
I welcome additions that promote clean, productive, and maintainable development.


🙏 Thanks

Thanks for exploring this repository!
Happy coding!

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

python_github_plus-1.1.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_github_plus-1.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file python_github_plus-1.1.0.tar.gz.

File metadata

  • Download URL: python_github_plus-1.1.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for python_github_plus-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c1e2af0fdeda3ae1ef8de70de5a7f56107895a874a6f3ce982990fa4d36b04b4
MD5 2240c2de6a4f3f4eb75689f2b58a8a1a
BLAKE2b-256 57e808987eef979edfbf2c733be76c9735db071756b1c033969eb261f7fd10e0

See more details on using hashes here.

File details

Details for the file python_github_plus-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_github_plus-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b76e5df7bfd41a23505de55d9178ae5a0251c7ab2dd30188c2cb5e817e9081c8
MD5 f96dc025d6d33bd16407e71f3fbb68f7
BLAKE2b-256 4533d672049a458beb8a1a89316e855b9b704ef72e4071fddcebf9afb921270c

See more details on using hashes here.

Supported by

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