I happen to write a lot of python code dealing with git repositories. Currently I am calling the git
command line tool from python and interpret the output.
This solution really doesn’t scale well. Can you recommend a python library that wraps git functionality?
I have found three:
- GitPython: Seems to work well, but it is in maintenance mode, unlikely to be improved. It also does not have any type hints making working with it annoying.
- pygit2: Seems well supported and has type hints. But it also seems very low level and pretty tedious to use.
- dulwich: Looks very promising feature wise but I’m unsure how well it is supported. It seems like an ambitious project being largely done by just one person.
I read through the docs of pygit2, how is it too low level compared to using direct console output?
if you need complex workflows, couldn’t they be built over the convenience of the library?
Maybe pygit2 is indeed the way to go. When I looked into it a while back it looked very low level like it only implemented the git plumbing. But maybe I looked at the wrong part of the docs, because it doesn’t look too bad.
Honestly if you already know all the git commands? I’d use sh
You’d still only get strings as returns. No objects modeling git concepts.
Fair point, I usually use exit codes
I used pygit2 a few years ago and it was easy. Can’t complain.
With no more details? I’d go with Dulwich.
libgit2
is overly picky about inputs and can’t be hacked apart at all, and this affects its bindings too. I recently found myself monkey-patching Dulwich to allow otherwise-forbidden characters in refs, and this would have been fundamentally impossible with anything on top oflibgit2
.Sounds like pygit2 is the move until dulwich has a bit more support.