{"id":16642927,"url":"https://github.com/nir0s/python-packer","last_synced_at":"2025-07-03T14:37:55.757Z","repository":{"id":30998452,"uuid":"34556835","full_name":"nir0s/python-packer","owner":"nir0s","description":"A Packer interface for Python","archived":false,"fork":false,"pushed_at":"2022-02-15T09:53:12.000Z","size":64,"stargazers_count":27,"open_issues_count":11,"forks_count":20,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-13T08:06:57.285Z","etag":null,"topics":["hashicorp","packer","python","python-packer"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nir0s.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-25T05:36:47.000Z","updated_at":"2024-10-01T10:36:26.000Z","dependencies_parsed_at":"2022-08-26T08:20:40.101Z","dependency_job_id":null,"html_url":"https://github.com/nir0s/python-packer","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nir0s%2Fpython-packer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nir0s%2Fpython-packer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nir0s%2Fpython-packer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nir0s%2Fpython-packer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nir0s","download_url":"https://codeload.github.com/nir0s/python-packer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221816556,"owners_count":16885356,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hashicorp","packer","python","python-packer"],"created_at":"2024-10-12T08:06:50.133Z","updated_at":"2024-10-28T10:23:12.250Z","avatar_url":"https://github.com/nir0s.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"python-packer\n=============\n\n[![Build Status](https://travis-ci.org/nir0s/python-packer.svg?branch=master)](https://travis-ci.org/nir0s/python-packer)\n[![PyPI](http://img.shields.io/pypi/dm/python-packer.svg)](http://img.shields.io/pypi/dm/python-packer.svg)\n[![PypI](http://img.shields.io/pypi/v/python-packer.svg)](http://img.shields.io/pypi/v/python-packer.svg)\n\n\nA Python interface for [packer.io](http://www.packer.io)\n\n## Packer version\n\nThe interface has been developed vs. Packer v0.7.5.\n\n\n## Installation\n\nYou must have Packer installed prior to using this client though as installer class is provided to install packer for you.\n\n```shell\n pip install python-packer\n\n # or, for dev:\n pip install https://github.com/nir0s/python-packer/archive/master.tar.gz\n```\n\n## Usage Examples\n\n### [Packer.build()](https://www.packer.io/docs/command-line/build.html)\n\n```python\nimport packer\n\npackerfile = 'packer/tests/resources/packerfile.json'\nexc = []\nonly = ['my_first_image', 'my_second_image']\nvars = {\"variable1\": \"value1\", \"variable2\": \"value2\"}\nvar_file = 'path/to/var/file'\npacker_exec_path = '/usr/bin/packer'\n\np = packer.Packer(packerfile, exc=exc, only=only, vars=vars,\n                  var_file=var_file, exec_path=packer_exec_path)\np.build(parallel=True, debug=False, force=False)\n```\n\n\n### [Packer.fix()](https://www.packer.io/docs/command-line/fix.html)\n\n```python\n...\n\np = packer.Packer(packerfile, ...)\noutput_file = 'packer/tests/resources/packerfile_fixed.json'\nprint(p.fix(output_file))\n```\n\nThe `output_file` parameter will write the output of the `fix` function to a file.\n\n\n### [Packer.inspect()](https://www.packer.io/docs/command-line/inspect.html)\n\nA `-machine-readable` (mrf) argument is provided.\n\nIf the `mrf` argument is set to `True`, the output will be parsed and an object containing the parsed output will be exposed as a dictionary containing the components:\n\n```python\n...\n\np = packer.Packer(packerfile, ...)\nresult = p.inspect(mrf=True)\nprint(result.parsed_output)\n# print(result.stdout) can also be used here\n\n# output:\n\"variables\": [\n  {\n    \"name\": \"aws_access_key\",\n    \"value\": \"{{env `AWS_ACCESS_KEY_ID`}}\"\n  },\n  {\n    \"name\": \"aws_secret_key\",\n    \"value\": \"{{env `AWS_ACCESS_KEY`}}\"\n  }\n],\n\"provisioners\": [\n  {\n    \"type\": \"shell\"\n  }\n],\n\"builders\": [\n  {\n    \"type\": \"amazon-ebs\",\n    \"name\": \"amazon\"\n  }\n]\n```\n\nIf the `mrf` argument is set to `False`, the output will not be parsed but rather returned as is:\n\n```python\n...\n\np = packer.Packer(packerfile, ...)\nresult = p.inspect(mrf=True)\nprint(result.stdout)\n\n# output:\nOptional variables and their defaults:\n\n  aws_access_key          = {{env `AWS_ACCESS_KEY_ID`}}\n  aws_secret_key          = {{env `AWS_ACCESS_KEY`}}\n\nBuilders:\n\n  amazon                   (amazon-ebs)\n\nProvisioners:\n\n  shell\n\n...\n\n```\n\n\n### [Packer.push()](https://www.packer.io/docs/command-line/push.html)\n\nYou must be logged into Atlas to use the `push` function:\n\n```python\n...\n\np = packer.Packer(packerfile, ...)\natlas_token = 'oi21mok3mwqtk31om51o2joj213m1oo1i23n1o2'\np.push(create=True, token=atlas_token)\n```\n\n### [Packer.validate()](https://www.packer.io/docs/command-line/validate.html)\n\n```python\n...\n\np = packer.Packer(packerfile, ...)\np.validate(syntax_only=False)\n```\n\n### Packer.version()\n\n```python\n...\n\np = packer.Packer(packerfile, ...)\nprint(p.version())\n```\n\n### PackerInstaller.install()\n\nThis installs packer to `packer_path` using the `installer_path` and verifies that the installation was successful.\n\n```python\n\npacker_path = '/usr/bin/'\ninstaller_path = 'Downloads/packer_0.7.5_linux_amd64.zip'\n\np = packer.Installer(packer_path, installer_path)\np.install()\n```\n\n## Shell Interaction\n\nThe [sh](http://amoffat.github.io/sh/) Python module is used to execute Packer.\nAs such, return values from all functional methods (`validate`, `build`, etc..) other than the `version` method\nwill return an `sh` execution object. This is meant for you to be able to read stdout, stderr, exit codes and more after executing the commands. With the progression of `python-packer` less abstract objects will return and more concise return values will be provided.\n\nAdditionally, to verify that all errors return with as much info as possible, error handling is done gently. Most errors will raise an `sh` exception so that you're able to interact with them. Again, as this module progresses, these exceptions will be handled properly.\n\n\n## Testing\n\nPlease contribute. Currently tests are not really developed.\n\n```shell\ngit clone git@github.com:nir0s/python-packer.git\ncd python-packer\npip install tox\ntox\n```\n\n## Contributions..\n\n..are always welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnir0s%2Fpython-packer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnir0s%2Fpython-packer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnir0s%2Fpython-packer/lists"}