Git URL Parse

0.14.0 · active · verified Thu Apr 09

giturlparse is a Python module designed for parsing and rewriting Git repository URLs. It extracts components like host, owner, repository name, and platform from various Git URL formats (HTTPS, SSH, Git protocol). The current version is 0.14.0, with a release cadence that is active but not rigidly frequent, focusing on feature additions and bug fixes as needed.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates parsing different Git URL formats and accessing their components. It also shows how to use the rewrite feature introduced in version 0.14.0 to modify repository details and generate new URLs.

from giturlparse import parse

# Example 1: GitHub SSH URL
url_ssh = parse('git@github.com:nephila/giturlparse.git')
print(f"SSH URL: {url_ssh.url}")
print(f"Owner: {url_ssh.owner}, Name: {url_ssh.name}, Platform: {url_ssh.platform}")

# Example 2: GitLab HTTPS URL with username:token
url_https = parse('https://user:token@gitlab.com/group/repo.git')
print(f"HTTPS URL: {url_https.url}")
print(f"Owner: {url_https.owner}, Name: {url_https.name}, Resource: {url_https.resource}")

# Example 3: Rewriting a URL (feature from v0.14.0)
parsed_url = parse('git@github.com:oldowner/oldrepo.git')
rewritten_url = parsed_url.rewrite(owner='newowner', name='newrepo')
print(f"Rewritten URL (SSH): {rewritten_url.format('ssh')}")
print(f"Rewritten URL (HTTPS): {rewritten_url.format('https')}")

view raw JSON →