{"id":13338347,"url":"https://github.com/Deviluc/python-tree-sitter","last_synced_at":"2025-03-11T09:30:53.822Z","repository":{"id":87882828,"uuid":"177289867","full_name":"Deviluc/python-tree-sitter","owner":"Deviluc","description":"A python wrapper around the tree-sitter c-api (using swig)","archived":false,"fork":false,"pushed_at":"2019-03-23T22:10:54.000Z","size":351,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-23T20:15:26.362Z","etag":null,"topics":["ast","java","parser","parser-library","python","python3","swig","tree-sitter"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Deviluc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-03-23T13:05:24.000Z","updated_at":"2019-03-23T22:10:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"bfc91046-eccf-423b-b62b-3d5667f12f84","html_url":"https://github.com/Deviluc/python-tree-sitter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deviluc%2Fpython-tree-sitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deviluc%2Fpython-tree-sitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deviluc%2Fpython-tree-sitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deviluc%2Fpython-tree-sitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Deviluc","download_url":"https://codeload.github.com/Deviluc/python-tree-sitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243007020,"owners_count":20220760,"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":["ast","java","parser","parser-library","python","python3","swig","tree-sitter"],"created_at":"2024-07-29T19:16:18.031Z","updated_at":"2025-03-11T09:30:53.813Z","avatar_url":"https://github.com/Deviluc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# python-tree-sitter\nA wrapper around the c-api of tree-sitter using swig\n\n## Building and installing\nRequires python 3.7m\n\n### Building api\n\n```./build.sh```\n\n### Building java parser\n```./build_java.sh```\n\n### Install\n*Warning*: currently both the api and java part must have been built first!\n```sudo python setup.py install```\n\n\n## Usage\n```\nfrom tree_sitter_api import Parser\nfrom tree_sitter_java import tree_sitter_java\njavalang = tree_sitter_java()\nparser = api.Parser()\nparser.set_language(javalang)\ntree = parser.parse_string(\"package com.example; public class Main { public static void main(final String[] args) { return; } }\")\nroot_node = tree.root_node()\nfor node in root_node:\n    print(node.string())\n```\n\n### Parser (tree_sitter_api.Parser)\nUsed to parse source code from an input source (currently only strings)\n\n| Method                    | Arguments / Return    | Description                                           |\n| ------------------------- | --------------------- | ------------------------------------------------------|\n| Constructor               | None / Parser         | Creates a new parser                                  |\n| set_language              | TSLanguage            | Set the language to parse                             |\n| get_logger                | None / TSLogger       | Returns the logger used (c-var)                       |\n| print_dot_graphs          | int                   | ???                                                   |\n| halt_on_error             | bool                  | Abort on first error                                  |\n| parse                     | TSInput, Tree / Tree  | Currently not supported                               |\n| parse_string              | String, Tree / Tree   | Parse string into a tree                              |\n| get_cancel_flag           | None / String         | ???                                                   |\n| set_cancel_flag           | String                | ???                                                   |\n| get_timeout_micros        | None / int            | Time until abort in micro secs                        |\n| set_timeout_micros        | int                   | Set time until abort                                  |\n| reset                     | None                  | Reset the parser settings ???                         |\n| set_included_ranges       | [Range]               | Set ranges to parse (multi languages in one file)     |\n| get_included_ranges       | None / [Range]        | Returns the ranges the parser will parse              |\n\n### Tree (tree_sitter_api.Tree)\nRepresents the parsed source code\n\n| Method                    | Arguments / Return    | Description                                           |\n| ------------------------- | --------------------- | ----------------------------------------------------- |\n| Constructor               | TSTree / Tree         | Creates a new Tree from a TSTree c-object             |\n| root_node                 | None / Node           | Returns the root node                                 |\n| edit                      | TSInputEdit           | Edit the tree before reparsing                        |\n| get_changed_ranges        | [Range]               | Returns the ranges that have been changed ???         |\n| print_dot_graph           | String                | Prints the dot graph into the file specified by path  |\n| language                  | TSLanguage            | Returns the source language                           |\n\n### Node (tree_sitter_api.Node)\nRepresents a node in the tree and a token in the source\n\n| Method                     | Arguments / Return    | Description                                              |\n| -------------------------- | --------------------- | -------------------------------------------------------- |\n| Constructor                | TSNode / Node         | Creates a new Node from a TSNode c-object                |\n| start_byte                 | None / int            | ???                                                      |\n| start_point                | None / Point          | Returns the start point of this Node                     |\n| end_byte                   | None / int            | ???                                                      |\n| end_point                  | None / Point          | Returns the end point of this Node                       |\n| symbol                     | None / TSSymbol       | ???                                                      |\n| type                       | None / String         | ???                                                      |\n| string                     | None / String         | String representation                                    |\n| is_null                    | None / bool           | Whether this node is null or not                         |\n| is_named                   | None / bool           | Whether this node is named or anonymous                  |\n| is_missing                 | None / bool           | ???                                                      |\n| has_changes                | None / bool           | Whether this node is part of a changed Range             |\n| has_error                  | None / bool           | Whether this node is erroneous                           |\n| parent                     | None / Node           | Returns the parent Node                                  |\n| child                      | int / Node            | Returns the n-th child (equivalent to `node[i]`)         |\n| named_child                | int / Node            | Returns the n-th named child                             |\n| child_count                | None / int            | Returns the number of childs (equivalent to `len(node)`) |\n| named_child_count          | None / int            | Returns the number of named childs                       |\n| next_sibling               | None / Node           | Returns the next sibling of this Node                    |\n| next_named_sibling         | None / Node           | Returns the next named sibling of this Node              |\n| prev_sibling               | None / Node           | Returns the previous sibling of this Node                |\n| prev_named_sibling         | None / Node           | Returns the previous named sibling of this Node          |\n| first_child_for_byte       | int / Node            | Returns the first child with the provided byte (?)       |\n| first_named_child_for_byte | int / Node            | Returns the first named child with the provided byte (?) |\n| descendant_for_byte_range  | int,int / Node        | ???                                                      |\n| named_descendant_for_byte_range | int,int / Node   | ???                                                      |\n| descendant_for_point_range | Point,Point / Node    | ???                                                      |\n| named_descendant_for_point_range | Point,Point / Node | ???                                                   |\n| edit                       | TSInputEdit           | Edit this Node                                           |\n\n### TreeCursor (tree_sitter_api.TreeCursor)\nRepresents a cursor for tree-traversal\n\n| Method                        | Arguments / Return    | Description                                           |\n| ----------------------------- | --------------------- | ----------------------------------------------------- |\n| Constructor                   | TSTreeCursor / TreeCursor | Creates a TreeCursor from a TSTreeCursor          |\n| reset                         | None                  | Reset position                                        |\n| current_node                  | None / Node           | Returns the current node                              |\n| goto_parent                   | None / bool           | Goes to the parent node and returns the success       |\n| goto_next_sibling             | None / bool           | Goes to the next sibling node and returns the success |\n| goto_first_child              | None / bool           | Goes to the first child node and returns the success  |\n| goto_first_child_for_byte     | int / bool            | Goes to the first child with the provided byte and returns the success |\n\n### Language\nTODO\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDeviluc%2Fpython-tree-sitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDeviluc%2Fpython-tree-sitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDeviluc%2Fpython-tree-sitter/lists"}