{"id":18468783,"url":"https://github.com/pycqa/baron","last_synced_at":"2025-04-08T09:07:10.544Z","repository":{"id":7573524,"uuid":"8928074","full_name":"PyCQA/baron","owner":"PyCQA","description":"IDE allow you to refactor code, Baron allows you to write refactoring code.","archived":false,"fork":false,"pushed_at":"2021-12-09T03:34:37.000Z","size":2635,"stargazers_count":292,"open_issues_count":57,"forks_count":50,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-17T11:10:03.054Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://baron.pycqa.org","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PyCQA.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","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":"2013-03-21T12:19:00.000Z","updated_at":"2025-02-26T21:24:55.000Z","dependencies_parsed_at":"2022-09-05T02:11:11.512Z","dependency_job_id":null,"html_url":"https://github.com/PyCQA/baron","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyCQA%2Fbaron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyCQA%2Fbaron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyCQA%2Fbaron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyCQA%2Fbaron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PyCQA","download_url":"https://codeload.github.com/PyCQA/baron/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809962,"owners_count":20999816,"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":[],"created_at":"2024-11-06T10:08:10.662Z","updated_at":"2025-04-08T09:07:10.518Z","avatar_url":"https://github.com/PyCQA.png","language":"Python","readme":"Introduction\n============\n\nBaron is a Full Syntax Tree (FST) library for Python. By opposition to an [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree) which\ndrops some syntax information in the process of its creation (like empty lines,\ncomments, formatting), a FST keeps everything and guarantees the operation\n\u003ccode\u003efst\\_to\\_code(code\\_to\\_fst(source\\_code)) == source\\_code\u003c/code\u003e.\n\nRoadmap\n=======\n\nCurrent roadmap is as boring as needed:\n\n* bug fixs\n* new small features (walker pattern, maybe code generation) and performance improvement.\n\nInstallation\n============\n\n    pip install baron\n\nBasic Usage\n===========\n\n```python\nfrom baron import parse, dumps\n\nfst = parse(source_code_string)\nsource_code_string == dumps(fst)\n```\n\nUnless you want to do low level things, **use\n[RedBaron](https://github.com/PyCQA/redbaron) instead of using Baron\ndirectly**. Think of Baron as the \"bytecode of python source code\" and RedBaron\nas some sort of usable layer on top of it.\n\nIf you don't know what Baron is or don't understand yet why it might be\nuseful for you, read the [« Why is this important? » section](#why-is-this-important).\n\nDocumentation\n=============\n\nBaron documentation is available on [Read The Docs](http://baron.readthedocs.io/en/latest/).\n\nContributing\n============\n\nIf you want to implement new grammar elements for newer python versions, here\nare the documented steps for that:\nhttps://github.com/PyCQA/baron/blob/master/add_new_grammar.md\n\nAlso note that reviewing most grammar modifications takes several hours of\nadvanced focusing (we can't really afford bugs here) so don't despair if you PR\nseems to be hanging around, sorry for that :/\n\nAnd thanks in advance for your work!\n\nFinancial support\n=================\n\nBaron and RedBaron are a very advanced piece of engineering that requires a lot\nof time of concentration to work on. Until the end of 2018, the development\nhas been a full volunteer work mostly done by [Bram](https://github.com/psycojoker),\nbut now, to reach the next level and bring those projects to the stability and\nquality you expect, we need your support.\n\nYou can join our contributors and sponsors on our transparent\n[OpenCollective](https://opencollective.com/redbaron), every contribution will\ncount and will be mainly used to work on the projects stability and quality but\nalso on continuing, on the side, the R\u0026D side of those projects.\n\nOur supporters\n--------------\n\n\n[![badge with number of supporters at tier I like this, keep going!](https://opencollective.com/redbaron/tiers/i-like-this,-keep-going!/badge.svg)\n![badge with number of supporters at tier it looks cool!](https://opencollective.com/redbaron/tiers/it-looks-cool!/badge.svg)\n![badge with number of supporters at tier Oh god, that saved me so much time!](https://opencollective.com/redbaron/tiers/oh-god,-that-saved-me-so-much-time!/badge.svg)](https://opencollective.com/redbaron/tiers/)\n\n\nWhy is this important?\n======================\n\nThe usage of a FST might not be obvious at first sight so let's consider a\nseries of problems to illustrate it. Let's say that you want to write a program that will:\n\n* rename a variable in a source file... without clashing with things that are not a variable (example: stuff inside a string)\n* inline a function/method\n* extract a function/method from a series of line of code\n* split a class into several classes\n* split a file into several modules\n* convert your whole code base from one ORM to another\n* do custom refactoring operation not implemented by IDE/rope\n* implement the class browser of smalltalk for python (the whole one where you can edit the code of the methods, not just showing code)\n\nIt is very likely that you will end up with the awkward feeling of writing\nclumpsy weak code that is very likely to break because you didn't thought about\nall the annoying special cases and the formatting keeps bothering you. You may\nend up playing with [ast.py](https://docs.python.org/3/library/ast.html) until\nyou realize that it removes too much information to be suitable for those\nsituations. You will probably ditch this task as simply too complicated and\nreally not worth the effort. You are missing a good abstraction that will take\ncare of all of the code structure and formatting for you so you can concentrate\non your task.\n\nThe FST tries to be this abstraction. With it you can now work on a tree which\nrepresents your code with its formatting. Moreover, since it is the exact\nrepresentation of your code, modifying it and converting it back to a string\nwill give you back your code only modified where you have modified the tree.\n\nSaid in another way, what I'm trying to achieve with Baron is a paradigm change in\nwhich writing code that will modify code is now a realist task that is worth\nthe price (I'm not saying a simple task, but a realistic one: it's still a\ncomplex task).\n\nOther\n-----\n\nHaving a FST (or at least a good abstraction build on it) also makes it easier\nto do code generation and code analysis while those two operations are already\nquite feasible (using [ast.py](https://docs.python.org/3/library/ast.html) \nand a templating engine for example).\n\nSome technical details\n======================\n\nBaron produces a FST in the form of JSON (and by JSON I mean Python lists\nand dicts that can be dumped into JSON) for maximum interoperability.\n\nBaron FST is quite similar to Python AST with some modifications to be more\nintuitive to humans, since Python AST has been made for CPython interpreter.\n\nSince playing directly with JSON is a bit raw I'm going to build an abstraction\non top of it that will looks like BeautifulSoup/jQuery.\n\nState of the project\n====================\n\nCurrently, Baron has been tested on the top 100 projects and the FST converts\nback exactly into the original source code. So, it can be considered quite\nstable, but it is far away from having been battle tested.\n\nSince the project is very young and no one is already using it except my\nproject, I'm open to changes of the FST nodes but I will quickly become\nconservative once it gets some adoption and will probably accept to\nmodify it only once or twice in the future with clear indications on how to\nmigrate.\n\nBaron is supporting python 2 grammar and up to python 3.7 grammar.\n\nTests\n=====\nRun either `py.test tests/` or `nosetests` in the baron directory.\n\nCommunity\n=========\n\nYou can reach us on [irc.freenode.net#baron](https://webchat.freenode.net/?channels=%23baron) or [irc.freenode.net##python-code-quality](https://webchat.freenode.net/?channels=%23%23python-code-quality).\n\nCode of Conduct\n===============\n\nAs a member of [PyCQA](https://github.com/PyCQA), Baron follows its [Code of Conduct](http://meta.pycqa.org/en/latest/code-of-conduct.html).\n\nMisc\n====\n[Old blog post announcing the project.](http://worlddomination.be/blog/2013/the-baron-project-part-1-what-and-why.html) Not that much up to date.\n","funding_links":["https://opencollective.com/redbaron","https://opencollective.com/redbaron/tiers/"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpycqa%2Fbaron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpycqa%2Fbaron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpycqa%2Fbaron/lists"}