{"library":"percy","title":"Percy Python Client","description":"The `percy` library provides a Python client for integrating visual regression testing with Percy (https://percy.io). It enables capturing snapshots of web pages during tests and uploading them to the Percy platform for visual comparison. It is currently at version 2.0.2, with an active development cycle that frequently includes minor improvements and occasional major versions for breaking changes.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install percy"],"cli":{"name":"percy","version":"sh: 1: percy: not found"}},"imports":["from percy.runner import PercyRunner","from percy.snapshot import percy_snapshot"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom percy.runner import PercyRunner\nfrom percy.snapshot import percy_snapshot\n\n# Percy requires a WebDriver instance (e.g., from Selenium or Playwright).\n# For this example, we'll use a mock driver.\nclass MockWebDriver:\n    def __init__(self):\n        self.title = \"Mock Page Title\"\n        self.current_url = \"http://localhost:8000/mock-page\"\n\n    def execute_script(self, script):\n        # Simulate returning page HTML or other script results\n        if \"document.documentElement.outerHTML\" in script:\n            return \"<html><body><h1>Hello from Percy!</h1></body></html>\"\n        return None\n\n# Ensure PERCY_TOKEN is set in your environment variables for actual uploads.\n# Example: export PERCY_TOKEN=\"YOUR_PERCY_TOKEN\"\npercy_token = os.environ.get('PERCY_TOKEN', 'YOUR_PERCY_TOKEN_IF_MISSING')\nif percy_token == 'YOUR_PERCY_TOKEN_IF_MISSING':\n    print(\"Warning: PERCY_TOKEN environment variable is not set. Snapshots will not be uploaded.\")\n\nrunner = PercyRunner()\ntry:\n    # Start a Percy build\n    runner.start_build()\n    print(\"Percy build started.\")\n\n    # Instantiate the mock driver\n    driver = MockWebDriver()\n\n    # Take a snapshot\n    percy_snapshot(driver, name=\"Example Snapshot 1\", widths=[768, 1280])\n    print(\"Snapshot 'Example Snapshot 1' taken.\")\n\n    # You can take multiple snapshots in a single build\n    # percy_snapshot(driver, name=\"Example Snapshot 2\", fullscreen=True)\n\nfinally:\n    # Finalize the Percy build\n    runner.finalize_build()\n    print(\"Percy build finalized.\")\n","lang":"python","description":"This quickstart demonstrates the basic lifecycle for using the Percy Python client: initialize `PercyRunner`, start a build, take one or more snapshots using a WebDriver instance, and then finalize the build. It requires a `PERCY_TOKEN` environment variable to successfully upload snapshots to Percy. A mock WebDriver is used to make the example runnable without a full browser setup.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}