{"id":19591580,"url":"https://github.com/kitanokitsune/s-expression-library-for-python","last_synced_at":"2025-11-21T13:03:37.928Z","repository":{"id":174191689,"uuid":"594855811","full_name":"kitanokitsune/S-expression-library-for-Python","owner":"kitanokitsune","description":"S-expression data structure parser/manipulator intended for parsing and manipulating lisp program, lisp data, netlists like EDIF and KiCAD, etc.","archived":false,"fork":false,"pushed_at":"2023-02-15T12:40:18.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-26T13:47:47.884Z","etag":null,"topics":["cad","edif","library","lisp","netlist","python","s-expressions"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kitanokitsune.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-29T20:51:28.000Z","updated_at":"2023-07-06T12:08:01.000Z","dependencies_parsed_at":"2023-08-23T12:18:05.899Z","dependency_job_id":null,"html_url":"https://github.com/kitanokitsune/S-expression-library-for-Python","commit_stats":null,"previous_names":["kitanokitsune/s-expression-library-for-python"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kitanokitsune/S-expression-library-for-Python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kitanokitsune%2FS-expression-library-for-Python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kitanokitsune%2FS-expression-library-for-Python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kitanokitsune%2FS-expression-library-for-Python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kitanokitsune%2FS-expression-library-for-Python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kitanokitsune","download_url":"https://codeload.github.com/kitanokitsune/S-expression-library-for-Python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kitanokitsune%2FS-expression-library-for-Python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285620632,"owners_count":27203062,"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","status":"online","status_checked_at":"2025-11-21T02:00:06.175Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["cad","edif","library","lisp","netlist","python","s-expressions"],"created_at":"2024-11-11T08:29:40.332Z","updated_at":"2025-11-21T13:03:37.899Z","avatar_url":"https://github.com/kitanokitsune.png","language":"Python","readme":"\nS-expression Library for Python - sxprlib.py\n=======================\n**S-expression Library for Python** is a library for Python to parse, read and manipulate *S-expression* data structures such as *lisp programs*, *lisp data*, netlists like *EDIF* and *KiCAD*, etc.  \n\nThis library was tested with [0644.edf](http://web.archive.org/web/20040812175715/http://mint.cs.man.ac.uk/Projects/gertrude/edif-files/index.html) EDIF file (12MB).\n\n\n# DEMO\n\n### Parse a text:\n```Python\n\u003e\u003e\u003e from sxprlib import *\n\u003e\u003e\u003e x = sxparse(\"(prices (apple 3.6) (orange 2.5))\")\n\u003e\u003e\u003e x\nCons(Symbol('prices'), Cons(Cons(Symbol('apple'), Cons(3.6, NIL)), Cons(Cons(Symbol('orange'), Cons(2.5, NIL)), NIL)))\n```\n### Print a S-expression\n```Python\n\u003e\u003e\u003e print(x)\n(prices (apple 3.6) (orange 2.5))\n\u003e\u003e\u003e sxpprint(x)\n\n(prices\n  (apple 3.6)\n  (orange 2.5))\n```\n### Read from a file:\n```Python\n\u003e\u003e\u003e with sxopen('sxsample.txt') as f:\n...     for s in f:\n...         sxpprint(s)\n...\n(prices\n  (apple 3.6)\n  (orange 2.5)\n  (banana 1.4))\n(netlist\n  (netname \"VCC\"\n    (node 1\n      (ref \"U1\")\n      (pin 1))\n    (node 2\n      (ref \"R1\")\n      (pin 2)))\n  (netname \"GND\"\n    (node 3\n      (ref \"U1\")\n      (pin 4))\n    (node 4\n      (ref \"R1\")\n      (pin 1))))\n(a b c d)\n```\n### List Access\n```Python\n\u003e\u003e\u003e print(x)\n(prices (apple 3.6) (orange 2.5))\n\u003e\u003e\u003e print(car(x))\nprices\n\u003e\u003e\u003e print(cdr(x))\n((apple 3.6) (orange 2.5))\n\u003e\u003e\u003e print(x[2])\n(orange 2.5)\n\u003e\u003e\u003e for v in x:\n...     print(v)\n...\nprices\n(apple 3.6)\n(orange 2.5)\n```\n### Convert from/to S-expression objects:\n```Python\n\u003e\u003e\u003e x\nCons(Symbol('prices'), Cons(Cons(Symbol('apple'), Cons(3.6, NIL)), Cons(Cons(Symbol('orange'), Cons(2.5, NIL)), NIL)))\n\u003e\u003e\u003e print(x)\n(prices (apple 3.6) (orange 2.5))\n\u003e\u003e\u003e l = sx2py(x)\n\u003e\u003e\u003e l\n['prices', ['apple', 3.6], ['orange', 2.5]]\n\u003e\u003e\u003e y = py2sx(l)\n\u003e\u003e\u003e y\nCons(Symbol('prices'), Cons(Cons(Symbol('apple'), Cons(3.6, NIL)), Cons(Cons(Symbol('orange'), Cons(2.5, NIL)), NIL)))\n```\n### Construct a S-expression data structure\n```Python\n\u003e\u003e\u003e z = Cons(Symbol(\"abc\"), 2)\n\u003e\u003e\u003e print(z)\n(abc . 2)\n\u003e\u003e\u003e z.cdr = Cons(3, NIL)\n\u003e\u003e\u003e print(z)\n(abc 3)\n\u003e\u003e\u003e w = mklist(10, z, String(\"xyz\"))\n\u003e\u003e\u003e print(w)\n(10 (abc 3) \"xyz\")\n```\n\n# Features\n**S-expression Library for Python** provides the following features:\n\n* [S-expression Primitives](./API.md#primitive-data-type)\n* [Text String Parser](./API.md#reader-and-parser-functions) (**sxparse** function and **SxprStringReader** class)\n* [File Reader](./API.md#reader-and-parser-functions) (**sxopen** function and **SxprFileReader** class)\n* [Standard Lisp Predicates](./API.md#standard-lisp-predicates) such as **null**, **consp**, **listp**, **atom**, etc.\n* [Standard Lisp Functions](./API.md#standard-lisp-functions) such as **car**, **cdr**, **cons**, **append**, etc.\n* [Utilities](./API.md#utility-functions) such as Converters (**py2sx**, **sx2py**) and Pretty-Print (**sxpprint**)\n* [Option Switches](./API.md#global-option-switches) to change parser behaviors\n\n\n# Requirement\n* Python 3\n\n\n# Installation\n* Place \"*sxprlib.py*\" and \"*ratcomplex.py*\" in the same directory where your program source is there.\n\n\n# Usage\n* Import \"*sxprlib.py*\" in your python code. Please see [*API Reference*](./API.md) for details.\n\n\n# Author\n* Kitanokitsune\n\n# License\nThis library is released under the [MIT license](https://en.wikipedia.org/wiki/MIT_License).  \n```text\nCopyright (c) 2023 Kitanokitsune\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkitanokitsune%2Fs-expression-library-for-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkitanokitsune%2Fs-expression-library-for-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkitanokitsune%2Fs-expression-library-for-python/lists"}