Fast, flexible and type-safe Git commands in Python.
Project description
🚀 Gitbolt
Fast, flexible and type-safe Git command execution in Python using subprocess.
✨ Features
- 🧠 Typed: All commands and options are statically type-checked.
- ⚡ Fast: Minimal abstractions over subprocess, runs directly on your system Git.
- 🧩 Composable: Git commands and options can be passed around as objects.
- 🔁 Overridable: Easily override environment variables and options in a chainable, readable manner.
- 📦 Lightweight: No dependencies on heavy Git libraries or C extensions.
- 🧰 Extensible: Future support for output transformers and other plugins.
- 🚨 Exception Handling: Raises any error as a Python-recognisable exception.
- 📤 Debuggable: Exceptions capture
stdout,stderr, and the return code of the run command. - 💤 Lazy Execution: Inherently lazily processed.
- 📄 Transparent Output: Returns a Git command's
stdoutas-is. - 🧪 Terminal Functions: Git subcommands are terminal functions.
- 🧼 Idiomatic Python: Write commands in idiomatic Python at compile-time and be confident they’ll execute smoothly at runtime.
📦 Installation
pip install gitbolt
💡 Motivation
Running system commands in Python can be tricky for the following reasons:
- Arguments sent to
subprocessmay not be typed correctly and result in runtime errors. - Argument groups may be mutually exclusive or required conditionally — again causing runtime issues.
- Errors from subprocess are often unhelpful and difficult to debug.
Also, using subprocess effectively means you must:
- Understand and manage process setup, piping, and teardown.
- Know your CLI command intricacies in depth.
This project exists to fix all that — with ergonomics, speed, and type-safety.
🎯 Project Goals
✅ Predictable Compile-Time Behavior
Type-checking ensures runtime safety.
✅ Ergonomic APIs
Make git command interfaces as ergonomic to the user as possible.
Provide versions of most used command combinations
git hash-object supports taking multiple files and outputs a hash per file. But in practice, it's most often used to write a single file to the Git object database and return its hash. To match this real-world usage, Gitbolt offers a more ergonomic method that accepts one file and returns one hash — while still giving you the flexibility to access the full range of git hash-object capabilities when needed.
Let subcommands be passed around as objects
Gitbolt lets you pass subcommands around as typed objects. This enables highly focused, minimal APIs — you can write functions that accept only the subcommands they truly need. This leads to cleaner logic, better separation of concerns, and compile-time guarantees that help prevent misuse.
import gitbolt
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
git = SimpleGitCommand()
version_subcmd = git.version_subcmd
add_subcmd = git.add_subcmd
def method_which_only_adds_a_file(add_subcmd: gitbolt.base.Add):
"""
This method only requires the `add` subcommand.
"""
...
method_which_only_adds_a_file(add_subcmd)
✅ Subcommands as Objects
git subcommands are modeled as terminal functions that return stdout.
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
git = SimpleGitCommand()
status_out = git.status_subcmd.status()
print(status_out)
🧠 Strong Typing Everywhere
Extensive use of type-hints ensures that invalid usages fail early — at compile-time. Write at compile-time and be sure that commands run error-free at runtime.
Allow users to set/unset/reset Git environment variables and main command options using typed, chainable, Pythonic methods — just before a subcommand is executed.
🧬 Git Environment Variables
🔁 Override a single Git env (e.g., GIT_TRACE)
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
git = SimpleGitCommand()
git = git.git_envs_override(GIT_TRACE=True)
🌐 Override multiple Git envs (e.g., GIT_TRACE, GIT_DIR, GIT_EDITOR)
from pathlib import Path
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
git = SimpleGitCommand()
git = git.git_envs_override(GIT_TRACE=1, GIT_DIR=Path('/tmp/git-dir/'), GIT_EDITOR='vim')
🪢 Chain multiple overrides fluently
from pathlib import Path
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
git = SimpleGitCommand()
overridden_git = git.git_envs_override(GIT_SSH=Path('/tmp/SSH')).git_envs_override(
GIT_TERMINAL_PROMPT=1,
GIT_NO_REPLACE_OBJECTS=True
)
re_overridden_git = overridden_git.git_envs_override(GIT_TRACE=True)
❌ Unset Git envs using a special UNSET marker
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
from vt.utils.commons.commons.core_py import UNSET
git = SimpleGitCommand()
overridden_git = git.git_envs_override(GIT_ADVICE=True, GIT_TRACE=True)
no_advice_unset_git = overridden_git.git_envs_override(GIT_TRACE=UNSET)
🔄 Reset Git envs by setting new values
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
git = SimpleGitCommand()
overridden_git = git.git_envs_override(GIT_TRACE=True)
git_trace_reset_git = overridden_git.git_envs_override(GIT_TRACE=False)
Allow users to set/unset/reset git main command options in typed and pythonic manner just before subcommand run to provide maximal flexibility.
⚙️ Git Main Command Options
🔁 Override a single Git opt (e.g., --no-replace-objects)
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
git = SimpleGitCommand()
git = git.git_opts_override(no_replace_objects=True)
🌐 Override multiple options (e.g., --git-dir, --paginate)
from pathlib import Path
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
git = SimpleGitCommand()
git = git.git_opts_override(no_replace_objects=True, git_dir=Path(), paginate=True)
🪢 Chain multiple option overrides fluently
from pathlib import Path
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
git = SimpleGitCommand()
overridden_git = git.git_opts_override(exec_path=Path('tmp')).git_opts_override(
noglob_pathspecs=True,
no_advice=True
).git_opts_override(
config_env={'auth': 'suhas', 'comm': 'suyog'}
)
re_overridden_git = overridden_git.git_opts_override(glob_pathspecs=True)
❌ Unset Git opts using a special UNSET marker
from pathlib import Path
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
from vt.utils.commons.commons.core_py import UNSET
git = SimpleGitCommand()
overridden_git = git.git_opts_override(exec_path=Path('tmp'), no_advice=True)
no_advice_unset_git = overridden_git.git_opts_override(no_advice=UNSET)
🔄 Reset Git opts by setting new values
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
git = SimpleGitCommand()
overridden_git = git.git_opts_override(no_advice=True)
no_advice_reset_git = overridden_git.git_opts_override(no_advice=False)
🔄 Run unchecked commands
At last, run unchecked commands in git.
Introduced in 0.0.0dev4 to
- experiment.
- have consistent interfaced commands run until all subcommands are provided by the library.
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
git = SimpleGitCommand()
git = git.git_opts_override(no_advice=True)
git.subcmd_unchecked.run(['--version']) # run the version option for git.
git.subcmd_unchecked.run(['version']) # run the version subcommand.
🔍 Transparent by Default
Output of git commands is returned as-is. No transformations unless explicitly requested. Transformers for formatting/parsing can be added later.
✅ Benefits Out-of-the-Box
- 🔄 Composable Git commands.
- 📤 Returns raw stdout.
- 🚨 Exceptions with full context.
- 💤 Lazy execution.
- 🧠 Strong typing and compile-time guarantees.
- 🧼 Idiomatic Python.
- 🧪 Terminal subcommands.
- 💣 Fail-fast on invalid usage.
📄 More Information
🚧 Future Goals
- Support
pygit2for direct, fast Git access. - Enable
porcelainsupport usingpygit2where required.
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 gitbolt-0.0.0.dev8.tar.gz.
File metadata
- Download URL: gitbolt-0.0.0.dev8.tar.gz
- Upload date:
- Size: 40.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30f16338b5c2608bbff8df2ffe4da9387afe9dc78381d21d08c4eb243c214ebf
|
|
| MD5 |
be68a10888e55d56554c8e0f91e3b49c
|
|
| BLAKE2b-256 |
fac9804b60cf4d661a90a0854a08ee930ea8b762a62b20f3ec6885d744285557
|
Provenance
The following attestation bundles were made for gitbolt-0.0.0.dev8.tar.gz:
Publisher:
python-publish.yml on Vaastav-Technologies/py-gitbolt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gitbolt-0.0.0.dev8.tar.gz -
Subject digest:
30f16338b5c2608bbff8df2ffe4da9387afe9dc78381d21d08c4eb243c214ebf - Sigstore transparency entry: 274357077
- Sigstore integration time:
-
Permalink:
Vaastav-Technologies/py-gitbolt@f68ea5a42f4a67a880cdf76e45713df76de23371 -
Branch / Tag:
refs/tags/v0.0.0dev8 - Owner: https://github.com/Vaastav-Technologies
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f68ea5a42f4a67a880cdf76e45713df76de23371 -
Trigger Event:
push
-
Statement type:
File details
Details for the file gitbolt-0.0.0.dev8-py3-none-any.whl.
File metadata
- Download URL: gitbolt-0.0.0.dev8-py3-none-any.whl
- Upload date:
- Size: 44.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
700d1f1f6a0945a58736d6dfefebd4736819a861723021a14168f8ff96880f92
|
|
| MD5 |
793d783e9eed0285cabb65e1a7381141
|
|
| BLAKE2b-256 |
69dc019cf86d25445e7e9fd4c957434d34ddef7cff12ef5970957d07645b772f
|
Provenance
The following attestation bundles were made for gitbolt-0.0.0.dev8-py3-none-any.whl:
Publisher:
python-publish.yml on Vaastav-Technologies/py-gitbolt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gitbolt-0.0.0.dev8-py3-none-any.whl -
Subject digest:
700d1f1f6a0945a58736d6dfefebd4736819a861723021a14168f8ff96880f92 - Sigstore transparency entry: 274357079
- Sigstore integration time:
-
Permalink:
Vaastav-Technologies/py-gitbolt@f68ea5a42f4a67a880cdf76e45713df76de23371 -
Branch / Tag:
refs/tags/v0.0.0dev8 - Owner: https://github.com/Vaastav-Technologies
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f68ea5a42f4a67a880cdf76e45713df76de23371 -
Trigger Event:
push
-
Statement type: