Lite, typed, python utilities for Git, SVN, Mercurial, etc.
Project description
libvcs provides a unified, typed, and pythonic interface for managing Git, Mercurial, and Subversion repositories. Whether you're building a deployment tool, a developer utility, or just need to clone a repo in a script, libvcs handles the heavy lifting.
It powers vcspull and simplifies VCS interactions down to a few lines of code.
Features at a Glance
- 🔄 Repository Synchronization: Clone, update, and manage local repository copies with a high-level API.
- 🛠 Command Abstraction: Speak fluent
git,hg, andsvnthrough fully-typed Python objects. - 🔗 URL Parsing: Robustly validate, parse, and manipulate VCS URLs (including SCP-style).
- 🧪 Pytest Fixtures: Batteries-included fixtures for spinning up temporary repositories in your test suite.
Installation
pip install libvcs
With uv:
uv add libvcs
Try it interactively:
uvx --with libvcs ipython
Tip: libvcs is pre-1.0. Pin a version range in projects to avoid surprises:
# pyproject.toml
dependencies = ["libvcs>=0.37,<0.38"]
Usage
1. Synchronize Repositories
Clone and update repositories with a consistent API, regardless of the VCS.
Learn more about Synchronization
import pathlib
from libvcs.sync.git import GitSync
# Define your repository
repo = GitSync(
url="https://github.com/vcs-python/libvcs",
path=pathlib.Path.cwd() / "libvcs",
remotes={
'gitlab': 'https://gitlab.com/vcs-python/libvcs'
}
)
# Clone (if not exists) or fetch & update (if exists)
result = repo.update_repo()
if result.ok:
print(f"Current revision: {repo.get_revision()}")
else:
for error in result.errors:
print(f"Sync failed at {error.step}: {error.message}")
2. Command Abstraction
Traverse repository entities intuitively with ORM-like filtering, then run targeted commands against them.
Learn more about Command Abstraction
import pathlib
from libvcs.cmd.git import Git
# Initialize the wrapper
git = Git(path=pathlib.Path.cwd() / 'libvcs')
# Run commands directly
git.clone(url='https://github.com/vcs-python/libvcs.git')
git.checkout(ref='master')
# Traverse branches with ORM-like filtering
git.branches.create('feature/new-gui')
print(git.branches.ls()) # Returns QueryList for filtering
# Target specific entities with contextual commands
git.remotes.set_url(name='origin', url='git@github.com:vcs-python/libvcs.git')
git.tags.create(name='v1.0.0', message='Release version 1.0.0')
3. URL Parsing
Stop writing regex for Git URLs. Let libvcs handle the edge cases.
from libvcs.url.git import GitURL
# Validate URLs
GitURL.is_valid(url='https://github.com/vcs-python/libvcs.git') # True
# Parse complex URLs
url = GitURL(url='git@github.com:vcs-python/libvcs.git')
print(url.user) # 'git'
print(url.hostname) # 'github.com'
print(url.path) # 'vcs-python/libvcs'
# Transform URLs
url.hostname = 'gitlab.com'
print(url.to_url()) # 'git@gitlab.com:vcs-python/libvcs.git'
4. Testing with Pytest
Writing a tool that interacts with VCS? Use our fixtures to keep your tests clean and isolated.
Learn more about Pytest Fixtures
import pathlib
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn
from libvcs.sync.git import GitSync
def test_my_git_tool(
create_git_remote_repo: CreateRepoPytestFixtureFn,
tmp_path: pathlib.Path
):
# Spin up a real, temporary Git server
git_server = create_git_remote_repo()
# Clone it to a temporary directory
checkout_path = tmp_path / "checkout"
repo = GitSync(path=checkout_path, url=f"file://{git_server}")
repo.obtain()
assert checkout_path.exists()
assert (checkout_path / ".git").is_dir()
Project Information
- Python Support: 3.10+
- VCS Support: Git (including AWS CodeCommit), Mercurial (hg), Subversion (svn)
- License: MIT
Links & Resources
- Documentation: libvcs.git-pull.com
- Source Code: github.com/vcs-python/libvcs
- Issue Tracker: GitHub Issues
- Changelog: History
- PyPI: pypi.org/project/libvcs
Support
Your donations fund development of new features, testing, and support.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file libvcs-0.39.0.tar.gz.
File metadata
- Download URL: libvcs-0.39.0.tar.gz
- Upload date:
- Size: 597.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c175c98cef75f3228e8c859f4af6d22b6cfe5843a2a29317e35c3745fd86a45
|
|
| MD5 |
e76b2b12bc3dad09ff4b8320988f2a49
|
|
| BLAKE2b-256 |
eba466ccfdb47f225c60e254476e4dfec2cb248ff1ee018bccce05a01fd5ae28
|
Provenance
The following attestation bundles were made for libvcs-0.39.0.tar.gz:
Publisher:
tests.yml on vcs-python/libvcs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libvcs-0.39.0.tar.gz -
Subject digest:
2c175c98cef75f3228e8c859f4af6d22b6cfe5843a2a29317e35c3745fd86a45 - Sigstore transparency entry: 927060645
- Sigstore integration time:
-
Permalink:
vcs-python/libvcs@65900736b285bb48787b1471ad10670c25b6533f -
Branch / Tag:
refs/tags/v0.39.0 - Owner: https://github.com/vcs-python
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
tests.yml@65900736b285bb48787b1471ad10670c25b6533f -
Trigger Event:
push
-
Statement type:
File details
Details for the file libvcs-0.39.0-py3-none-any.whl.
File metadata
- Download URL: libvcs-0.39.0-py3-none-any.whl
- Upload date:
- Size: 97.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b20514e57b53c02ce07d57c708b4b7828a632479b9ea393ebeba31e0377a5f0
|
|
| MD5 |
d87fec1c70ee9645f78dd2580bfd9d80
|
|
| BLAKE2b-256 |
6f60960cc0fa9b7df6dd9e6f89340629a902f068d25406f8828369d2bcac20f4
|
Provenance
The following attestation bundles were made for libvcs-0.39.0-py3-none-any.whl:
Publisher:
tests.yml on vcs-python/libvcs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libvcs-0.39.0-py3-none-any.whl -
Subject digest:
5b20514e57b53c02ce07d57c708b4b7828a632479b9ea393ebeba31e0377a5f0 - Sigstore transparency entry: 927060646
- Sigstore integration time:
-
Permalink:
vcs-python/libvcs@65900736b285bb48787b1471ad10670c25b6533f -
Branch / Tag:
refs/tags/v0.39.0 - Owner: https://github.com/vcs-python
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
tests.yml@65900736b285bb48787b1471ad10670c25b6533f -
Trigger Event:
push
-
Statement type: