fastgit
fastgit is a thin Python wrapper for the git CLI: one Git object whose attribute calls run git commands, so if you know git, you already know fastgit. There is no reimplementation of git internals and no object model to learn – commands return git’s own output as (subclassed) strs.
It is designed for interactive use and automation alike: errors print tersely by default (like git itself) or raise on request, exit codes that mean “no” rather than “failed” are returned normally, and passing sync=False gives an async client for servers and concurrent code.
Usage
Installation
Install latest from pypi
$ pip install fastgit
How to use
Create a Git for any directory; every command runs with that directory as its working tree. Method names map to git subcommands, and results come back as stripped strings:
import shutil, tempfile
td = tempfile.mkdtemp()
g = Git(td)
g.init(b='main')
'Initialized empty Git repository in /private/var/folders/51/b2_szf2945n072c0vj2cyty40000gn/T/tmp8zyj76q7/.git/'
(g.d/'.gitignore').mk_write('*.bak')
g.add('.gitignore')
g.commit(m='add .gitignore')
'[main (root-commit) 5113ce1] add .gitignore\n 1 file changed, 1 insertion(+)\n create mode 100644 .gitignore'
Keyword arguments become options: single-letter names are short options (n=1 → -n 1), longer names long options with underscores turned into dashes, and True passes the bare flag:
g.log(n=1, oneline=True)
'5113ce1 add .gitignore'
You can also pass path arguments after -- using the __ parameter:
g.log('--oneline', __=['.gitignore'])
'5113ce1 add .gitignore'
Frequent queries are properties:
g.current_branch, g.commits
('main', ['5113ce1 add .gitignore'])
A failed command prints git’s message and returns None; pass raise_exc=True (per call or at init) to raise instead. Where git uses exit 1 to mean “no” rather than “error” – like grep finding nothing – the output is returned as usual, with the code on .returncode:
res = g.grep('missing')
res.returncode
1
Pass sync=False for an async client: the same commands and properties, each returning an awaitable, so a server never blocks its event loop on git:
ag = Git(td, sync=False)
await ag.last_commit
'add .gitignore'
Metadata
Release files for fastgit 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastgit-0.1.3.tar.gz | 9.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastgit-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.4 kB
Release files / fastgit-0.1.3.tar.gz
| Download URL | fastgit-0.1.3.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77a61b6d10db467d3fc62dd52111c236cfb6c0ed04b4a5c171cdc1cab3169269
|
|
BLAKE2b-256 checksum How to use checksums |
ca6b61ded3b6b5d3329c54a33326dd7b0e60720eb3e5540e93280f2c306181c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / fastgit-0.1.3-py3-none-any.whl
| Download URL | fastgit-0.1.3-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
20d1fdf74209f98f88c5d7244074d2ff7ece4bab3657153af2475e8a79be3f91
|
|
BLAKE2b-256 checksum How to use checksums |
4da4bdda184558e2a183e9705241efdbbcff34ef0812801f0ccf8263f6b2edcd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|