{ "info": { "author": "Palo Alto Networks", "author_email": "techbizdev@paloaltonetworks.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 2.7", "Topic :: Internet", "Topic :: Security" ], "description": "# girolamo\n\nJSON/YAML serializable templates for dict-to-dict transformations.\n\n## Quickstart\n\n### Installation\n\n```shell\n$ pip install -r requirements-dev.txt\n$ pip install .\n```\n\n### Hello World !\n\n```python\nfrom girolamo import Template\n\nHELLO_WORLD_TPL = {\n 'a': 'Girolamo fecit',\n 'hw': {'$list-join': [' ', ['$$a', '$$b', '!']]},\n}\n\nDICTIN = {\n 'a': 'Hello',\n 'b': 'World'\n}\n\nctemplate = Template.compile(HELLO_WORLD_TPL)\ndictout = ctemplate.eval(data=DICTIN)\nprint dictout\n```\n\nResult\n\n```python\n{'a': 'Girolamo fecit', 'hw': 'Hello World !'}\n```\n\n### Templates in YAML/JSON\n\n*girolamo* templates can be directly represented in YAML:\n\n```yaml\na: Girolamo fecit\nhw:\n $list-join:\n - ' '\n - [$$a, $$b, '!']\n ```\n\n and JSON\n\n ```json\n {\n \"a\": \"Girolamo fecit\",\n \"hw\": {\n \"$list-join\": [\n \" \",\n [ \"$$a\", \"$$b\", \"!\" ]\n ]\n }\n}\n ```\n\n## Templates\n\nTemplates in *girolamo* are dictionaries. The value of each key in the template is an expression. Each key in the template becomes a key in the output dictionary with value the result of the evaluation of the associated expression.\n\n## Expressions\n\n|Expression *exp*|Value *eval(exp)*|\n|----------|-----|\n|*number*|The number|\n|*string*|The string|\n|*None*|*None*|\n|{ key1: *exp1*, key2: *exp2*, ... }|The dictionary { key1: *eval(exp1)*, key2: *eval(exp2)*, ... }|\n|[ *exp1*, *exp2*, ... ]|The list [ *eval(exp1)*, *eval(exp2)*, ... ]|\n|$$*key*|The value of *key* in the input dictionary|\n|$*symbol*|The value of *symbol* in the current environment|\n|{$*function*: [ *exp1*, *exp2*, ... ]}|The result of calling *function* with [ *eval(exp1)*, *eval(exp2)*, ... ]|\n|{$*function*: *exp1*}|The result of calling *function* with [ *eval(exp1)* ]|\n\n### if...then...else\n\nThe special function *if* can be used for conditionals. The format is:\n\n```python\n{\n \"$if\": [\n pred,\n conseq,\n alt\n ]\n}\n```\n\nwhere *pred*, *conseq* and *alt* are expressions. If *pred* is true then *conseq* is evaluated and the result is returned, otherwise *conseq* is evaluated and the result returned.\n\nExample:\n\n```yaml\n# is_network is true if __indicator is an IP Network\nis_network:\n $if:\n - { $is-unicast: $$__indicator }\n - false\n - true\n```\n\n### Match\n\nThe special function *match* can be used to select between multiple options. The format is:\n\n```python\n{\n \"$match\": [\n var,\n [pred1, exp1], [pred2, exp2], ...],\n default\n ]\n}\n```\n\nThe expression *var* is evaluated and the value compared in order with the predicate expressions *pred1*, *pred2*, ... When a predicate expression is true the associated expression is evaluated and the result is returned. If none of the predicate expressions is true *default* is evaluated and the result returned.\n\nExample:\n\n```yaml\n# ip_version is set to 4 if the type key of the input dictionary is \"IPv4\"\n# set to 6 if the type key is \"IPv6\"\n# set to null/None otherwise\nip_version:\n $match:\n - $$type\n - [[\"IPv4\", 4], [\"IPv6\", 6]]\n - null\n```\n\n### Assignments\n\nThe special function *define* can be used to assign a value to a symbol in the current environment. The format is:\n\n```python\n{\n \"$define\": [\n symbol,\n value\n ]\n}\n```\n\nThe expression *value* is evaluated and the result assigned to *symbol* in the current environment. Return value of *define* is *None*.\n\n### Lambdas\n\nThe special function *lambda* can be used to define anonymous functions. The format is:\n\n```python\n{\n \"$lambda\": [\n [ formal1, formal2, ... ],\n body\n ]\n}\n```\n\nIf a single formal is required the needed could also be:\n\n```python\n{\n \"$lambda\": [\n formal1,\n body\n ]\n}\n```\n\n### Quick lambdas\n\nA function call with paramater *$_* evaluates in a lambda function. Basically the format:\n\n```python\n{\n \"$function\": [ exp1, exp2, \"$_\" ]\n}\n```\n\nis equivalent to:\n\n```python\n{\n \"$lambda\": [\n \"$_\",\n { \"$function\": [ exp1, exp2, \"$_\" ] }\n ]\n}\n```\n\n## Globals in template ($ Keys)\n\nA template key starting with *$* is handled as the definition of a global symbol that can be used in the evaluation of all the template keys.\n\nExample:\n\n```python\n{\n # defines the interesting-fields symbol\n \"$interesting-fields\": [\n \"phishme_threatType\",\n \"phishme_label\",\n \"phishme_threatDetailURL\",\n \"recordedfuture_entityurl\",\n \"proofpoint_etintelligence_max_score\",\n \"proofpoint_etintelligence_categories\",\n \"bambenekconsulting_description\",\n \"bambenekconsulting_info\"\n ]\n}\n```", "description_content_type": null, "docs_url": null, "download_url": null, "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/jtschichold/girolamo", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "girolamo", "package_url": "https://pypi.org/project/girolamo/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/girolamo/", "project_urls": { "Homepage": "https://github.com/jtschichold/girolamo" }, "release_url": "https://pypi.org/project/girolamo/0.1b1/", "requires_dist": null, "requires_python": null, "summary": "A Dict-to-Dict YAML/JSON serializable template language", "version": "0.1b1" }, "last_serial": 2576103, "releases": { "0.1b1": [] }, "urls": [] }