{"library":"mercurial","title":"Mercurial SCM","description":"Mercurial is a fast, scalable, and distributed revision control (version control) system designed for efficient handling of projects of any size. It is primarily implemented in Python, with performance-critical parts in C and Rust. The library is actively maintained with regular releases, with version 7.2.1 being the latest stable release as of April 1, 2026.","language":"python","status":"active","last_verified":"Sun May 17","install":{"commands":["pip install mercurial"],"cli":{"name":"hg","version":"Mercurial Distributed SCM (version 7.2.2)"}},"imports":["from mercurial import ui, hg"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport shutil\nfrom mercurial import ui, hg\n\n# Create a dummy directory for the repository\nrepo_path = 'my_test_repo'\nif os.path.exists(repo_path):\n    shutil.rmtree(repo_path)\nos.makedirs(repo_path)\n\n# Initialize a new Mercurial repository\nrepo = hg.repository(ui.ui(), repo_path, create=True)\nprint(f\"Repository initialized at: {repo_path}\")\n\n# Create a file\nfile_path = os.path.join(repo_path, 'hello.txt')\nwith open(file_path, 'w') as f:\n    f.write('Hello, Mercurial!')\nprint(f\"Created file: {file_path}\")\n\n# Add and commit the file\n# Note: Mercurial's internal API for add/commit can be complex.\n# This example uses `add` and then `commit` via the repo object.\n# For simpler CLI-like interaction, consider `hglib` or `hgapi`.\n# The 'add' command is implicitly handled by `commit` for untracked files in newer versions/contexts, \n# but explicitly adding first is generally safer for robust scripts.\nrepo.add([file_path])\nrepo.commit(text='Initial commit', user='Test User <test@example.com>')\n\nprint(\"File committed.\")\n\n# Verify the commit (optional: run hg log in the directory to confirm)\n# You would typically interact with changesets, manifests, etc. for more complex verification.\nlogs = repo.changelog.read() # Read changelog to get revision info\nif logs:\n    latest_rev = repo.changelog.tip()\n    print(f\"Latest revision: {latest_rev.node()[:12]}\")\n    print(f\"Commit message: {latest_rev.description()}\")\n\n# Clean up the test repository (optional)\nshutil.rmtree(repo_path)\nprint(f\"Cleaned up {repo_path}\")\n","lang":"python","description":"This quickstart demonstrates how to programmatically initialize a Mercurial repository, create a file, and commit it using the internal `mercurial` Python API. This approach is typically used for developing Mercurial extensions or deeply embedded functionality. For simpler command-line interactions from Python, external libraries like `hglib` (for command server) or `hgapi` (wrapping CLI) might be considered as they offer a more stable API than the internal `mercurial` modules.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-17","installed_version":"7.2.2","pypi_latest":"7.2.2","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":3.1,"avg_import_s":0.79,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"mercurial","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.74,"mem_mb":20,"disk_size":"48.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"mercurial","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.6,"import_time_s":0.59,"mem_mb":20,"disk_size":"53M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"mercurial","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.96,"mem_mb":22.9,"disk_size":"55.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"mercurial","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.8,"import_time_s":0.89,"mem_mb":22.9,"disk_size":"59M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"mercurial","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.85,"mem_mb":22.2,"disk_size":"45.9M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"mercurial","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.9,"import_time_s":0.85,"mem_mb":22.2,"disk_size":"50M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"mercurial","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.89,"mem_mb":22.7,"disk_size":"45.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"mercurial","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3,"import_time_s":0.82,"mem_mb":22.7,"disk_size":"50M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"mercurial","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.68,"mem_mb":20.1,"disk_size":"48.2M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"mercurial","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.4,"import_time_s":0.59,"mem_mb":20.1,"disk_size":"52M"}]}}