Skip to main content

fastgit

fastgit is a Python wrapper for the git command line, for use in scripts and interactive sessions. You call git subcommands as Python methods and pass options as keyword arguments.

Commands run through the installed git executable and return its text output. There is no separate object model for repositories and commits. Both synchronous and asynchronous clients are available.

Usage

Installation

Install latest from pypi

$ pip install fastgit

How to use

Create a Git object for the directory you want to work in. Every command runs in that directory. The default local runner expands ~ and resolves relative paths. A custom runner receives the supplied directory unchanged. Results have leading and trailing whitespace stripped:

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 command-line options:

  • Single-letter names produce short options, such as n=1 for -n 1.
  • Longer names produce long options, with underscores replaced by dashes.
  • A value of True passes the flag without a value.
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'])

Command output is returned in a str subclass with the exit code in .returncode. A failed command prints git’s message and returns None. Pass raise_exc=True to raise an exception instead. You can set this per call or when creating the client.

Some git commands use exit code 1 for a negative result. For example, grep returns 1 when nothing matches. fastgit returns the output for these results without treating them as failures:

res = g.grep('missing')
res.returncode
1

Pass sync=False for an async client. Its commands and properties return awaitables. Waiting for git does not block the event loop:

ag = Git(td, sync=False)
await ag.last_commit
'add .gitignore'

Metadata

Release files for fastgit 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastgit 0.1.4
File Size Uploaded
fastgit-0.1.4.tar.gz 9.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastgit 0.1.4
File Interpreter ABI Platform
fastgit-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 20.6 kB

Release files / fastgit-0.1.4.tar.gz

Download URL fastgit-0.1.4.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a54c00f31157501007d57181bf0df12740c2bb6dda2d5527fce8dd234157a2e4
BLAKE2b-256 checksum
How to use checksums
6310e8c58e210d28d8aebe2eef99186861ea1eabf7ff0c81c22f6cc84f098bfb
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.4-py3-none-any.whl

Download URL fastgit-0.1.4-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac1c51b22700039ee3367f660a1acf8e34ad50877c34056ad7a7251d76fc96aa
BLAKE2b-256 checksum
How to use checksums
87fa22eb098261ffa189c27aa8385a778d28ca3e4da7c7520d6fea3a4c4c8f27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page