VCS fastimport/fastexport parser
Project Links
Meta
Author: Canonical Ltd
Maintainer: Jelmer Vernooij
Requires Python: >=3.9
Classifiers
Development Status
- 4 - Beta
License
- OSI Approved :: GNU General Public License v2 or later (GPLv2+)
Programming Language
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
- Python :: Implementation :: CPython
- Python :: Implementation :: PyPy
Operating System
- POSIX
Topic
- Software Development :: Version Control
python-fastimport
This package provides a parser for and generator of the Git fastimport format. (https://www.kernel.org/pub/software/scm/git/docs/git-fast-import.html)
Installation
pip install fastimport
Example
Here's a simple example of how to parse a fastimport stream:
from fastimport import parser
# Parse a fastimport stream from a file
with open('export.dat', 'rb') as f:
p = parser.ImportParser(f)
for cmd in p.iter_commands():
if cmd.name == b'commit':
print(f"Commit to branch: {cmd.ref}")
print(f"Author: {cmd.author}")
print(f"Message: {cmd.message}")
elif cmd.name == b'blob':
print(f"Blob mark: {cmd.mark}, size: {len(cmd.data)}")
And here's how to generate a fastimport stream:
from fastimport import commands
# Create a new blob
blob = commands.BlobCommand(
mark=b'1',
data=b'Hello, World!\n',
lineno=0
)
# Create a commit
commit = commands.CommitCommand(
ref=b'refs/heads/main',
mark=b'2',
author=(b'John Doe', b'john@example.com', 1234567890, 0),
committer=(b'John Doe', b'john@example.com', 1234567890, 0),
message=b'Initial commit\n',
from_=None,
merges=None,
file_iter=[
commands.FileModifyCommand(
path=b'hello.txt',
mode=0o100644,
dataref=b':1',
data=None
)
]
)
# Write to a fastimport stream
with open('import.dat', 'wb') as f:
f.write(bytes(blob))
f.write(b'\n')
f.write(bytes(commit))
0.9.16
Sep 30, 2025
0.9.15
Sep 30, 2025
0.9.14
Aug 23, 2021
0.9.13
Jun 09, 2021
0.9.12
May 02, 2021
0.9.11
Apr 12, 2021
0.9.10
Apr 11, 2021
0.9.9
Apr 10, 2021
0.9.8
Apr 15, 2018
0.9.7
Apr 15, 2018
0.9.6
Apr 19, 2016
0.9.5
Apr 18, 2016
0.9.4
Jul 05, 2014
0.9.3
Mar 01, 2014
0.9.2
Sep 22, 2013
Wheel compatibility matrix
Files in release
No dependencies