Registry / devops / ghrepo

ghrepo

JSON →
library0.7.1pypypi✓ verified 85d ago

A Python library for parsing and constructing GitHub repository URLs and specifiers (e.g., 'owner/repo'). Current version 0.7.1, requires Python >=3.8. Released on PyPI with moderate cadence.

pip install ghrepo
INSTALL
IMPORT
SIG · GHREPO
G
ghrepo
devopspythonv0.7.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GHRepo
from ghrepo import GHRepo
parse
from ghrepo import parse

Basic usage: create GHRepo from URL or specifier, get components and URLs.

from ghrepo import GHRepo, parse # Parse a URL repo = GHRepo('https://github.com/owner/repo') print(repo.owner, repo.name) # owner repo # Construct from specifier repo2 = GHRepo('owner/repo') print(repo2.url) # https://github.com/owner/repo # Parse using function repo3 = parse('owner/repo') print(repo3.full_name) # owner/repo # Auth (example with token) import os token = os.environ.get('GITHUB_TOKEN', '') if token: repo4 = GHRepo('owner/repo', token=token) print(repo4.clone_url) # https://x-access-token:...@github.com/owner/repo.git
Debug
Known issues
deprecatedThe 'from_url' class method is deprecated in favor of GHRepo() constructor directly.
fix
Use GHRepo(url) instead of GHRepo.from_url(url).
affects: >=0.7.0
gotchaStrings with trailing slash cause ValueError. URLs must not end with a slash.
fix
Strip trailing slashes before passing to GHRepo or parse().
affects: all
gotchaGitHub Enterprise URLs are not supported. Only github.com (or github.com subdomains?) tested.
fix
Use a dedicated library like github3.py for enterprise support, or manually handle.
affects: all
Errors
Common errors & fixes
ValueError: Could not parse 'owner/repo/' as a GitHub repo
Input string has trailing slash, which is invalid for this library.
fix
Strip trailing slash: GHRepo('owner/repo'.rstrip('/'))
AttributeError: 'str' object has no attribute 'owner'
User called GHRepo as a function returning string? Actually GHRepo is a class, but if someone writes repo = GHRepo('url') and then repo = 'something', they get this.
fix
Ensure proper usage: repo = GHRepo('url') then use repo.owner, not reassign repo to string.
Upgrade
Version history
0.7.1latest on PyPI · released Dec 1, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
ghrepo — pip install ghrepo · libregistry