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. Trailing newlines are stripped from results:

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

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

Built distribution (wheel)

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

Total release size: 20.8 kB

Release files / fastgit-0.1.6.tar.gz

Download URL fastgit-0.1.6.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c568b7cdffab5d1a8675f9defd7273f70d4b8ed2e8e8eed3f30bb5c1d3518074
BLAKE2b-256 checksum
How to use checksums
346ed60a7c5d9de93c481a8ae494b5b6b78f6bf9fc6f0e8defc453f81d7d16f0
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.6-py3-none-any.whl

Download URL fastgit-0.1.6-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b227754658fdf34c9b3820454f5f0169bd7143cd2b9ce25b7e87e2ddfa53c6e
BLAKE2b-256 checksum
How to use checksums
38dadc5305afcb3f04d121a1d2166d2d26b41284d6f9f11531b00ae6a80e9222
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Security for fastgit 0.1.6

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