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.5

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.5
File Size Uploaded Provenance Actions
fastgit-0.1.5.tar.gz 10.0 kB Without provenance Details for fastgit-0.1.5.tar.gz

Built distribution (wheel)

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

Total release size: 20.7 kB

Release files / fastgit-0.1.5.tar.gz

Download URL fastgit-0.1.5.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8728e6dfb70de57a8f58758d4e66192f3450a3177a7a56ee0c532fcd24d13d9e
BLAKE2b-256 checksum
How to use checksums
404ed898a6a01e00daf66d675321616720e1b55939389585b98c7e9411dc36e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / fastgit-0.1.5-py3-none-any.whl

Download URL fastgit-0.1.5-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
afdf5db61deff69d5267b74be8ce90a0645a2772f32da9d1e02e5432842a836f
BLAKE2b-256 checksum
How to use checksums
6238e16a28317852ae806172b831766a44a59d8dd6686e7448b024aa06bbf47a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Security for fastgit 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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