{"id":5724,"library":"smmap2","title":"smmap2 - Shared Memory Map","description":"smmap2 is a mirror package on PyPI for the `smmap` library, specifically distributing version 3.0.1 of `smmap` under the name `smmap2`. It provides an efficient way to memory-map data, particularly for large files, and is primarily intended as an internal dependency for specific versions of `GitPython` or projects requiring this exact older version. The upstream `smmap` project (at `gitpython-developers/smmap`) has since progressed to version 5.x.x.","status":"active","version":"3.0.1","language":"en","source_language":"en","source_url":"https://github.com/gitpython-developers/smmap2","tags":["memory-mapping","gitpython","low-level","mirror-package"],"install":[{"cmd":"pip install smmap2","lang":"bash","label":"Install smmap2"}],"dependencies":[],"imports":[{"note":"Despite the package being named `smmap2` on PyPI, the Python import path for its modules is `smmap`.","wrong":"from smmap2 import SlidingWindowMap","symbol":"SlidingWindowMap","correct":"from smmap import SlidingWindowMap"}],"quickstart":{"code":"import os\nimport mmap\nimport tempfile\nfrom smmap import SlidingWindowMap\n\n# Create a dummy file for memory mapping\ndata_to_map = b\"This is some test data that will be memory-mapped.\" * 10 # make it a bit larger\nfile_size = len(data_to_map)\n\n# Use tempfile to create a temporary file\nwith tempfile.NamedTemporaryFile(delete=False) as tmp_file:\n    tmp_file.write(data_to_map)\n    tmp_file_path = tmp_file.name\n\ntry:\n    # Open the file for reading\n    with open(tmp_file_path, \"rb\") as f:\n        # Create an mmap object for the file\n        m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)\n\n        # Create a SlidingWindowMap instance\n        # For this example, we'll map the entire file into a single window\n        window_size = file_size\n        s = SlidingWindowMap(m, begin=0, size=file_size, window_size=window_size)\n\n        # Access data through the sliding window map\n        read_data = s[0:file_size]\n        print(f\"Read data length: {len(read_data)}\")\n        print(f\"First 50 bytes: {read_data[:50].decode()}\")\n\n        assert read_data == data_to_map\n        print(\"Data successfully read and verified.\")\n\n        s.close()\n        m.close()\n\nfinally:\n    # Clean up the temporary file\n    if os.path.exists(tmp_file_path):\n        os.remove(tmp_file_path)\n","lang":"python","description":"Demonstrates how to initialize and use `SlidingWindowMap` to read data from a memory-mapped file. It creates a temporary file, maps it into memory, and then accesses the data via `SlidingWindowMap`."},"warnings":[{"fix":"Always use `from smmap import ...` for importing modules and classes from the `smmap2` package.","message":"The PyPI package is named `smmap2`, but the Python import statement uses `from smmap import ...`. Attempting `from smmap2 import ...` will result in an `ImportError`.","severity":"gotcha","affected_versions":"3.0.1"},{"fix":"If you need the latest `smmap` functionality or broad Python compatibility, install `smmap` directly via `pip install smmap`. Be aware of potential API differences between v3.x and v5.x.","message":"The `smmap2` package (v3.0.1) is an older, specific version of the `smmap` library. It does not track the latest developments of the upstream `smmap` project (which is currently at v5.x.x at `gitpython-developers/smmap`). Users expecting the latest `smmap` features or fixes will be disappointed.","severity":"gotcha","affected_versions":"3.0.1"},{"fix":"For new projects or modern Python environments, prefer `pip install smmap`. If you must use `smmap2`, thoroughly test its compatibility with your specific Python version.","message":"The `smmap2` package (v3.0.1) specifies very old Python compatibility requirements (`>=2.6, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*`). While it might still run on modern Python versions (3.6+), it is not actively tested or guaranteed to be fully compatible. For modern Python applications, the newer `smmap` v5.x.x is recommended.","severity":"deprecated","affected_versions":"3.0.1"},{"fix":"Consider if you truly need this low-level memory mapping functionality directly, or if a higher-level library that depends on `smmap` (like `GitPython`) would be more appropriate for your use case.","message":"This package is primarily intended as an internal dependency for specific versions of `GitPython` and similar projects. It is not typically designed for direct, standalone application development, and its API documentation might be sparse or outdated.","severity":"gotcha","affected_versions":"3.0.1"},{"fix":"If migrating from `smmap2` to `smmap` (v5.x.x), review the `smmap` changelog and update your code to reflect the new API and usage patterns.","message":"The `smmap` library underwent significant changes between versions 3.x (as mirrored by `smmap2`) and 5.x. Code written for `smmap` v3.0.1 will likely not be directly compatible with `smmap` v5.x.x without modification due to API changes.","severity":"breaking","affected_versions":"3.0.1"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}