{"id":4548,"library":"gitdb2","title":"GitDB2","description":"gitdb2 is a 'mirror package' that provides the `gitdb` library, which implements a pure-Python object database for Git. It handles the storage and retrieval of Git objects (blobs, trees, commits, tags) and is a core dependency for libraries like `GitPython`. The current version is 4.0.12, with releases driven primarily by `GitPython`'s needs and Python version compatibility.","status":"active","version":"4.0.12","language":"en","source_language":"en","source_url":"https://github.com/gitpython-developers/gitdb","tags":["git","database","version control","dependency","object database","smmap"],"install":[{"cmd":"pip install gitdb2","lang":"bash","label":"Install gitdb2"}],"dependencies":[{"reason":"Provides memory mapping utilities used by gitdb for efficient object storage and retrieval.","package":"smmap","optional":false}],"imports":[{"note":"The `gitdb2` package provides the `gitdb` namespace. Direct imports should always be from `gitdb`, not `gitdb2`.","wrong":"from gitdb2 import GitDB","symbol":"GitDB","correct":"from gitdb import GitDB"},{"note":"The `gitdb2` package provides the `gitdb` namespace. Direct imports should always be from `gitdb`, not `gitdb2`.","wrong":"from gitdb2 import IStream","symbol":"IStream","correct":"from gitdb import IStream"}],"quickstart":{"code":"import tempfile\nimport os\nimport hashlib\nfrom gitdb import GitDB, IStream\n\n# Create a temporary directory for the GitDB\nwith tempfile.TemporaryDirectory() as temp_dir:\n    # GitDB expects an 'objects' directory within its base path\n    db_path = os.path.join(temp_dir, 'objects')\n    os.makedirs(db_path) # Ensure the 'objects' directory exists\n\n    # Initialize GitDB\n    db = GitDB(db_path)\n    print(f\"GitDB initialized at: {db_path}\")\n\n    # Create some dummy content for a Git 'blob' object\n    content = b\"Hello, GitDB! This is a test blob.\\n\"\n    size = len(content)\n    object_type = b\"blob\"\n\n    # Git objects are stored as: type + space + size + null byte + content\n    header = object_type + b\" \" + str(size).encode('ascii') + b\"\\0\"\n    stored_data = header + content\n    sha1 = hashlib.sha1(stored_data).hexdigest()\n\n    # Create an IStream object for input\n    # IStream takes type (bytes), size (int), and data (bytes)\n    istream = IStream(object_type, size, content)\n\n    # Store the object in the GitDB\n    # The put method returns an object with the hexsha attribute\n    stored_sha = db.put(istream).hexsha\n    print(f\"Stored object with SHA1: {stored_sha}\")\n\n    # Verify the SHA1 matches our expectation\n    print(f\"Expected SHA1: {sha1}\")\n    assert stored_sha == sha1\n\n    # Retrieve the object using its SHA1 hash\n    retrieved_istream = db.get(stored_sha)\n    retrieved_content = retrieved_istream.read()\n\n    print(f\"Retrieved content type: {retrieved_istream.type.decode()}\")\n    print(f\"Retrieved content size: {retrieved_istream.size}\")\n    print(f\"Retrieved content: {retrieved_content.decode().strip()}\")\n\n    # Assert retrieved data matches original\n    assert retrieved_istream.type == object_type\n    assert retrieved_istream.size == size\n    assert retrieved_content == content\n\n    print(\"Object stored and retrieved successfully.\")","lang":"python","description":"This quickstart demonstrates how to initialize a `GitDB` instance, store a 'blob' object, and then retrieve it using its SHA1 hash. It utilizes `tempfile` for creating a temporary database location."},"warnings":[{"fix":"Always use `import gitdb` or `from gitdb import ClassName` for all functionality.","message":"The `gitdb2` PyPI package provides the `gitdb` Python package namespace. When importing symbols, always use `from gitdb import ...` instead of `from gitdb2 import ...`.","severity":"gotcha","affected_versions":"All versions of gitdb2"},{"fix":"Ensure your project's Python interpreter version matches the requirements of the `gitdb2` version you are using. Upgrade `gitdb2` to the latest version for Python 3.8+.","message":"Python version support changes: `gitdb2` regularly drops support for End-of-Life (EOL) Python versions and adds support for newer ones. For example, version 4.0.11 dropped Python 3.7 and added 3.12.","severity":"breaking","affected_versions":"4.0.11 and later (for Python 3.7 removal); check release notes for specific version compatibility."},{"fix":"If you need Git functionality, consider using `GitPython` which builds upon `gitdb` and provides a higher-level API. Only use `gitdb` directly if you require low-level Git object database interaction.","message":"`gitdb2` is primarily an internal dependency for `GitPython` and other Git-related libraries. While it can be used directly, its API might not be as user-friendly or stable for general application development compared to its role as a library component.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use a virtual environment to isolate dependencies. If conflicts persist, check the dependency tree of your project for other libraries requiring `smmap` and try to align their versions, or consider alternative solutions.","message":"`gitdb` has a hard dependency on `smmap>=5.0.0`. Conflicts can arise if other libraries in your environment require an older or incompatible version of `smmap`.","severity":"gotcha","affected_versions":"All versions requiring `smmap>=5.0.0`"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}