# Using git from Python

7 messages from 2008-05-08 to 2008-05-14. Participants: Asheesh Laroia, Eric Hanchrow, David Aguilar, Dill, Steve Frécinaux.
Thread: https://gitlist.dev/t/13425

## Asheesh Laroia, 2008-05-08 00:18

Subject: Using git from Python
Message-ID: <alpine.DEB.1.10.0805071612510.26718@sf.creativecommons.org>
URL: https://gitlist.dev/e/alpine.DEB.1.10.0805071612510.26718%40sf.creativecommons.org

```
>From a Python app, I want to read and write a git repository.  It seems 
from Luiz Fernando's post at http://blog.cpu.eti.br/?p=91 that the efforts 
to Pythonize libgit have stalled.

On #git, I was advised to simply call the git command suite.  That's fine, 
and I can do it using the subprocess module in Python - but since I 
figured others may have done this also, does anyone know of a Python 
module that wraps some git commands?  I'm thinking if others have gone 
down this path, they might have code that e.g. raises Exceptions when the 
git commands fail for some reason.

What have others on this list done lately for using git from Python?

-- Asheesh.

-- 
You will reach the highest possible point in your business or profession.

```

## Eric Hanchrow, 2008-05-08 03:54

Subject: Re: Using git from Python
Message-ID: <87lk2l4fj5.fsf@offby1.atm01.sea.blarg.net>
URL: https://gitlist.dev/e/87lk2l4fj5.fsf%40offby1.atm01.sea.blarg.net
In-Reply-To: <alpine.DEB.1.10.0805071612510.26718@sf.creativecommons.org>

```
>>>>> "Asheesh" == Asheesh Laroia <asheesh@asheesh.org> writes:

    Asheesh> On #git, I was advised to simply call the git command
    Asheesh> suite.  

That's what I'd do ...  (I wonder if it was me who so advised you :-)

    Asheesh> That's fine ... but since I figured others may have done
    Asheesh> this also

As far as I can tell, there is exactly no downside to simply forking a
subprocess.  Why are you trying to avoid that?
                      
    Asheesh> raises Exceptions when the git commands fail for some
    Asheesh> reason.

If Popen doesn't already raise an exception when the child process
fails, then it's surely a simple matter to check the exit code, and
raise the exception yourself.

-- 
I write [from 5 AM to 7 AM] to discover what I think.  After
all, the bars aren't open that early.
        -- Daniel Boorstin, former Librarian of Congress

```

## David Aguilar, 2008-05-08 04:23

Subject: Re: Using git from Python
Message-ID: <402731c90805072123g764a3d56ia30035381c0950dd@mail.gmail.com>
URL: https://gitlist.dev/e/402731c90805072123g764a3d56ia30035381c0950dd%40mail.gmail.com
In-Reply-To: <87lk2l4fj5.fsf@offby1.atm01.sea.blarg.net>

```
On Wed, May 7, 2008 at 8:54 PM, Eric Hanchrow <offby1@blarg.net> wrote:
>     Asheesh> That's fine ... but since I figured others may have done
>     Asheesh> this also
>
>  As far as I can tell, there is exactly no downside to simply forking a
>  subprocess.  Why are you trying to avoid that?
>
>     Asheesh> raises Exceptions when the git commands fail for some
>     Asheesh> reason.
>
>  If Popen doesn't already raise an exception when the child process
>  fails, then it's surely a simple matter to check the exit code, and
>  raise the exception yourself.
>

There have been many questions about this lately.
For the impatient, grab git.py from the python-git directory of the
ugit project:

http://repo.or.cz/w/ugit.git?a=tree;f=python-git;h=1ef75cef116ce750b5bdf5dd38a4cf1ab2c1ce79;hb=b393c428cf156a7c5c75b18379676dbb534a76d8

http://repo.or.cz/w/ugit.git

I will work on making git.py a separate python-git project, upload it
to pypi, and create a separate repo for it very soon.

The interface is blazingly simple.  It is a 1:1 correspondance to the
git command line interface.  e.g. git.commit(F='/some/path.txt',
s=True)

There are many examples in the t/ directory and within the ugit
project itself.  Let me know offline if you have any questions.  The
documentation could probably use some work.

-- 
 David

```

## Dill, 2008-05-10 06:52

Subject: Re: Using git from Python
Message-ID: <9b013f14-c193-41bc-923f-5f9a09d4fd60@56g2000hsm.googlegroups.com>
URL: https://gitlist.dev/e/9b013f14-c193-41bc-923f-5f9a09d4fd60%4056g2000hsm.googlegroups.com
In-Reply-To: <alpine.DEB.1.10.0805071612510.26718@sf.creativecommons.org>

```
Also check out: http://gitorious.org/projects/git-python/

Asheesh Laroia wrote:
> From a Python app, I want to read and write a git repository.  It seems
> from Luiz Fernando's post at http://blog.cpu.eti.br/?p=91 that the efforts
> to Pythonize libgit have stalled.
>
> On #git, I was advised to simply call the git command suite.  That's fine,
> and I can do it using the subprocess module in Python - but since I
> figured others may have done this also, does anyone know of a Python
> module that wraps some git commands?  I'm thinking if others have gone
> down this path, they might have code that e.g. raises Exceptions when the
> git commands fail for some reason.
>
> What have others on this list done lately for using git from Python?
>
> -- Asheesh.
>
> --
> You will reach the highest possible point in your business or profession.
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

```

## Asheesh Laroia, 2008-05-12 18:17

Subject: Re: Using git from Python
Message-ID: <alpine.DEB.1.00.0805121116560.6810@swallowtail>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0805121116560.6810%40swallowtail
In-Reply-To: <9b013f14-c193-41bc-923f-5f9a09d4fd60@56g2000hsm.googlegroups.com>

```
On Fri, 9 May 2008, Dill wrote:

> Also check out: http://gitorious.org/projects/git-python/

That looks very friendly and object-oriented.  It doesn't seem to have 
write support, based on a quick look - is that right?  Is write support a 
feature you're considering adding?

-- Asheesh.

-- 
Is a person who blows up banks an econoclast?

```

## Steve Frécinaux, 2008-05-13 07:39

Subject: Re: Using git from Python
Message-ID: <f35478f50805130039s6dfe9411j63411f2f7a7db6c3@mail.gmail.com>
URL: https://gitlist.dev/e/f35478f50805130039s6dfe9411j63411f2f7a7db6c3%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.0805121116560.6810@swallowtail>

```
Hi,

It is very fun, because I started my own project ten days ago with
similar goals: making python bindings for git. Since I didn't have
much imagination at that time, I called it "pygit", eventually
renaming it later with a better name.

While being quite similar to git-python at first glance, its primary
goal is to feel as pythonic as possible, and to be suitable for
porcelainish scripts (in such, it is quite low-level wrt the
operations it allows, and has repository writing at the top of its
todo list)...

Despite it seems a bit older than gitpython if you look at the commit
history, it seems less mature, probably because it's written mostly
from scratch and not a raw port of the ruby bindings. For instance,
docs are still missing, which is why I didn't announce it to this list
yet. It seems it is roughly on par with git-python feature-wise,
though.

I hope you'll like this one too ;-)

Ah, I forgot: here it is: http://code.istique.net/?p=pygit.git

(If you get an error, try reloading the page, the server gets crappy sometimes)

PS. Comments welcome.

On Mon, May 12, 2008 at 8:17 PM, Asheesh Laroia <asheesh@asheesh.org> wrote:
> On Fri, 9 May 2008, Dill wrote:
>
>
> > Also check out: http://gitorious.org/projects/git-python/
> >
>
>  That looks very friendly and object-oriented.  It doesn't seem to have
> write support, based on a quick look - is that right?  Is write support a
> feature you're considering adding?

```

## Steve Frécinaux, 2008-05-14 06:10

Subject: Re: Using git from Python
Message-ID: <f35478f50805132310p2b94b128o3a6f391849ffb8ec@mail.gmail.com>
URL: https://gitlist.dev/e/f35478f50805132310p2b94b128o3a6f391849ffb8ec%40mail.gmail.com
In-Reply-To: <20080513205021.GI2592@inocybe.teonanacatl.org>

```
On Tue, May 13, 2008 at 10:50 PM, Todd Zullinger <tmz@pobox.com> wrote:
> Hi Steve,
>
> I saw that you started some python bindings for git and thought I'd
> take a peak (even though I don't have a need for such a thing at the
> moment :).  I notice that the COPYING file is GPLv2, but the comments
> in all the files say License: LGPL 2.  Which one is incorrect?

Mmh. The LGPL one. I think I've copied the wrong file in and forgot to
double-test ;-)

```
