{"id":26368760,"url":"https://github.com/bindreams/varformat","last_synced_at":"2026-02-15T16:06:50.172Z","repository":{"id":228015319,"uuid":"661419733","full_name":"bindreams/varformat","owner":"bindreams","description":"Format and parse strings with ${variables} of any syntax.","archived":false,"fork":false,"pushed_at":"2025-03-07T15:36:55.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-05T01:35:19.732Z","etag":null,"topics":["formatting","python3","string-interpolation","string-manipulation"],"latest_commit_sha":null,"homepage":"","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/bindreams.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-07-02T19:33:02.000Z","updated_at":"2025-03-07T15:37:02.000Z","dependencies_parsed_at":"2024-03-17T18:28:34.051Z","dependency_job_id":"9d0c3fd0-e73c-4844-ac7f-fc5db1496344","html_url":"https://github.com/bindreams/varformat","commit_stats":null,"previous_names":["andreasxp/dollarvar","andreasxp/varformat","bindreams/varformat"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/bindreams/varformat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bindreams%2Fvarformat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bindreams%2Fvarformat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bindreams%2Fvarformat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bindreams%2Fvarformat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bindreams","download_url":"https://codeload.github.com/bindreams/varformat/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bindreams%2Fvarformat/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29483447,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-15T15:33:17.885Z","status":"ssl_error","status_checked_at":"2026-02-15T15:32:53.698Z","response_time":118,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["formatting","python3","string-interpolation","string-manipulation"],"created_at":"2025-03-16T22:48:59.304Z","updated_at":"2026-02-15T16:06:50.155Z","avatar_url":"https://github.com/bindreams.png","language":"Python","readme":"# Varformat Library\nVarformat can format and un-format (parse) strings containing various styles of variables.\n```python\n\u003e\u003e\u003e import varformat as vf\n\u003e\u003e\u003e vf.format('Hi ${name}!', name='mom')\n'Hi mom!'\n\u003e\u003e\u003e vf.parse('archive-${date}.tar.gz', 'archive-1970-01-01.tar.gz')\n{'date': '1970-01-01'}\n\n\u003e\u003e\u003e from varformat.formats import python\n\u003e\u003e\u003e python.format('Classic {style}', style='python braces')\n'Classic python braces'\n\n\u003e\u003e\u003e from varformat.formats import posix_shell as sh\n\u003e\u003e\u003e sh.format('POSIX compliant $style', style='dollar variables')\n'POSIX compliant dollar variables'\n\n```\n\n## Getting Started\nVarformat is available to install via pip:\n```\npip install varformat\n```\n\nWhen installed, the modules `varformat` and `varformat.formats` will be available. Global functions `format`, `vformat`, and `parse` represent the default formmatter with a `${}` style:\n```python\n\u003e\u003e\u003e import varformat as vf\n\u003e\u003e\u003e vf.format('my name ${name}', name='jeff')\n'my name jeff'\n\n```\n\nIf it is necessary to specify keys which are not valid python identifiers, such as numbers or string with spaces, you can use `vformat` instead:\n```python\n\u003e\u003e\u003e import varformat as vf\n\u003e\u003e\u003e vf.vformat('My three favorite foods: ${1}, ${2}, and ${1} again',\n...     {'1': 'pizza', '2': 'chocolate'})\n'My three favorite foods: pizza, chocolate, and pizza again'\n\n```\n\n`vformat` also supports keyword arguments to customize formatting behavior. `partial_ok` (default `False`) and `extra_ok` (default: `True`) control whether it is allowed to provide less (or more) arguments than the format string requires. `ambiguity_check` (default: `False`) will raise an error if your resulting string will be ambiguous:\n```python\n\u003e\u003e\u003e import varformat as vf\n\u003e\u003e\u003e vf.vformat('package-${os}-${arch}', {'os': 'ubuntu-22.04', 'arch': 'amd64'}, ambiguity_check=True)\nTraceback (most recent call last):\n    ...\nvarformat.AmbiguityError: refusing to format because parsing would be ambiguous:\n  could be: {'os': 'ubuntu-22.04', 'arch': 'amd64'}\n        or: {'os': 'ubuntu', 'arch': '22.04-amd64'}\n\n```\n\nThe `parse` function, which performs the inverse of `vformat`, also supports `ambiguity_check` (default: `True`):\n```python\n\u003e\u003e\u003e import varformat as vf\n\u003e\u003e\u003e vf.parse('package-${os}-${arch}', 'package-ubuntu-22.04-amd64')\nTraceback (most recent call last):\n    ...\nvarformat.AmbiguityError: parsing is ambiguous:\n  could be: {'os': 'ubuntu-22.04', 'arch': 'amd64'}\n        or: {'os': 'ubuntu', 'arch': '22.04-amd64'}\n\n```\n\nYou can of course set `ambiguity_check` to `False`, and `parse` will parse using the regular expression rules (greedily).\n\n### Other formatters\nModule `varformat.formats` contains formatters with other syntaxes:\n- `varformat.formats.posix_shell` follows POSIX shell variable rules: it disallows numeric identifiers, identifiers with spaces, but allows referencing variables like `$var` in addition to `${var}`;\n- `varformat.formats.python` follows classic python format string rules (e.g. `{var}`).\n\nYou can define your own formatter with your own custom syntax by subclassing either `varformat.RegexFormatter` and defining a regular expression that detects placeholders, or `varformat.AbstractFormatter` and defining a parsing function. See class docstrings for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbindreams%2Fvarformat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbindreams%2Fvarformat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbindreams%2Fvarformat/lists"}