fastimport

Git Fastimport parser and generator in Python

Latest version: 0.9.16 registry icon
Maintenance score
40
Safety score
100
Popularity score
16
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
0.9.16 0 0 0 0 0
0.9.15 0 0 0 0 0
0.9.14 0 0 0 0 0
0.9.13 0 0 0 0 0
0.9.12 0 0 0 0 0
0.9.11 0 0 0 0 0
0.9.10 0 0 0 0 0
0.9.9 0 0 0 0 0
0.9.8 0 0 0 0 0
0.9.7 0 0 0 0 0
0.9.6 0 0 0 0 0
0.9.5 0 0 0 0 0
0.9.4 0 0 0 0 0
0.9.3 0 0 0 0 0
0.9.2 0 0 0 0 0
0.9.1 0 0 0 0 0
0.9.0 0 0 0 0 0

Stability
Latest release:

0.9.16 - This version may not be safe as it has not been updated for a long time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

GPL-2.0-or-later   -   GNU General Public License v2.0 or later

Not a wildcard

Not proprietary

OSI Compliant



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))