{"library":"shiv","title":"Shiv: Python Zipapp Builder","description":"Shiv is a command-line utility for building fully self-contained Python zipapps (.pyz files) in compliance with PEP 441. It packages a Python application, its dependencies, and a Python interpreter bootstrap into a single executable file. The current version is 1.0.8, with a release cadence of relatively frequent minor releases.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install shiv"],"cli":{"name":"shiv","version":"shiv, version 1.0.8"}},"imports":[],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import subprocess\nimport sys\nimport os\n\n# 1. Create a simple Python script to be packaged\nscript_content = \"\"\"\n# hello_app.py\nimport sys\ndef main():\n    print(f\"Hello from shiv zipapp! Python version: {sys.version.split()[0]}\")\n\nif __name__ == '__main__':\n    main()\n\"\"\"\nwith open(\"hello_app.py\", \"w\") as f:\n    f.write(script_content)\n\n# 2. Build the zipapp using shiv (assuming shiv is installed)\nprint(\"Building hello_app.pyz...\")\ntry:\n    subprocess.run(\n        [sys.executable, \"-m\", \"shiv\", \"-o\", \"hello_app.pyz\", \"-e\", \"hello_app:main\", \".\"],\n        check=True,\n        capture_output=True,\n        text=True\n    )\n    print(\"Zipapp built successfully.\")\nexcept subprocess.CalledProcessError as e:\n    print(f\"Error building zipapp: {e.stderr}\")\n    sys.exit(1)\n\n# 3. Execute the built zipapp\nprint(\"Executing hello_app.pyz...\")\ntry:\n    result = subprocess.run(\n        [sys.executable, \"hello_app.pyz\"],\n        check=True,\n        capture_output=True,\n        text=True\n    )\n    print(\"Zipapp output:\")\n    print(result.stdout.strip())\nexcept subprocess.CalledProcessError as e:\n    print(f\"Error executing zipapp: {e.stderr}\")\n    sys.exit(1)\nfinally:\n    # 4. Clean up generated files\n    if os.path.exists(\"hello_app.py\"):\n        os.remove(\"hello_app.py\")\n    if os.path.exists(\"hello_app.pyz\"):\n        os.remove(\"hello_app.pyz\")\n    print(\"Cleanup complete.\")","lang":"python","description":"This quickstart demonstrates how to create a simple Python script, package it into a self-contained zipapp using `shiv`, and then execute the resulting zipapp.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}