Name | python-jsx JSON |
Version |
0.2.0
JSON |
| download |
home_page | None |
Summary | JSX transpiler for Python |
upload_time | 2025-01-26 14:59:17 |
maintainer | None |
docs_url | None |
author | None |
requires_python | <=3.14,>=3.10 |
license | None |
keywords |
jsx
react
transpiler
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<p align="center">
<img src="logo_bungee_tint.svg" />
</p>
# PyJSX - Write JSX directly in Python
```python
# coding: jsx
from pyjsx import jsx, JSX
def Header(children, style=None, **rest) -> JSX:
return <h1 style={style}>{children}</h1>
def Main(children, **rest) -> JSX:
return <main>{children}</main>
def App() -> JSX:
return (
<div>
<Header style={{"color": "red"}}>Hello, world!</Header>
<Main>
<p>This was rendered with PyJSX!</p>
</Main>
</div>
)
```
## Installation
Get it via pip:
```sh
pip install python-jsx
```
## Minimal example (using the `coding` directive)
> [!TIP]
> There are more examples available in the [examples folder](examples).
There are two supported ways to seamlessly integrate JSX into your codebase.
One is by registering a custom codec shown here and the other by using a custom import hook shown [below](#minimal-example-using-an-import-hook).
```python
# hello.py
# coding: jsx
from pyjsx import jsx
def hello():
print(<h1>Hello, world!</h1>)
```
```python
# main.py
from pyjsx import auto_setup
from hello import hello
hello()
```
```sh
$ python main.py
<h1>Hello, word!</h1>
```
Each file containing JSX must contain two things:
- `# coding: jsx` directive - This tells Python to let our library parse the
file first.
- `from pyjsx import jsx` import. PyJSX transpiles JSX into `jsx(...)` calls so
it must be in scope.
To run a file containing JSX, the `jsx` codec must be registered first which can
be done with `from pyjsx import auto_setup`. This must occur before importing
any other file containing JSX.
## Minimal example (using an import hook)
> [!TIP]
> There are more examples available in the [examples folder](examples).
```python
# hello.px
from pyjsx import jsx
def hello():
print(<h1>Hello, world!</h1>)
```
```python
# main.py
from pyjsx import auto_setup
from hello import hello
hello()
```
```sh
$ python main.py
<h1>Hello, word!</h1>
```
Each file containing JSX must contain two things:
- The file extension must be `.px`
- `from pyjsx import jsx` import. PyJSX transpiles JSX into `jsx(...)` calls so
it must be in scope.
To be able to import `.px`, the import hook must be registered first which can
be done with `from pyjsx import auto_setup` (same as for the codec version). This must occur before importing any other file containing JSX.
## Supported grammar
The full [JSX grammar](https://facebook.github.io/jsx/) is supported.
Here are a few examples:
### Normal and self-closing tags
```python
x = <div></div>
y = <img />
```
### Props
```python
<a href="example.com">Click me!</a>
<div style={{"color": "red"}}>This is red</div>
<span {...props}>Spread operator</span>
```
### Nested expressions
```python
<div>
{[<p>Row: {i}</p> for i in range(10)]}
</div>
```
### Fragments
```python
fragment = (
<>
<p>1st paragraph</p>
<p>2nd paragraph</p>
</>
)
```
### Custom components
A custom component can be any function that takes `**kwargs` and
returns JSX or a plain string. The special prop `children` is a list
containing the element's children.
```python
def Header(children, **rest):
return <h1>{children}</h1>
header = <Header>Title</Header>
print(header)
```
## Prior art
Inspired by [packed](https://github.com/michaeljones/packed) and
[pyxl4](https://github.com/pyxl4/pyxl4).
Raw data
{
"_id": null,
"home_page": null,
"name": "python-jsx",
"maintainer": null,
"docs_url": null,
"requires_python": "<=3.14,>=3.10",
"maintainer_email": null,
"keywords": "JSX, React, transpiler",
"author": null,
"author_email": "Tomas Roun <tomas.roun8@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/ac/61/668cfcfee7d64d4f3d8f239628cbd086bf776b28ada7bdb5ff6115e3663c/python_jsx-0.2.0.tar.gz",
"platform": null,
"description": "<p align=\"center\">\n <img src=\"logo_bungee_tint.svg\" />\n</p>\n\n# PyJSX - Write JSX directly in Python\n\n```python\n# coding: jsx\nfrom pyjsx import jsx, JSX\n\ndef Header(children, style=None, **rest) -> JSX:\n return <h1 style={style}>{children}</h1>\n\ndef Main(children, **rest) -> JSX:\n return <main>{children}</main>\n\ndef App() -> JSX:\n return (\n <div>\n <Header style={{\"color\": \"red\"}}>Hello, world!</Header>\n <Main>\n <p>This was rendered with PyJSX!</p>\n </Main>\n </div>\n )\n```\n\n## Installation\n\nGet it via pip:\n\n```sh\npip install python-jsx\n```\n\n## Minimal example (using the `coding` directive)\n\n> [!TIP]\n> There are more examples available in the [examples folder](examples).\n\nThere are two supported ways to seamlessly integrate JSX into your codebase.\nOne is by registering a custom codec shown here and the other by using a custom import hook shown [below](#minimal-example-using-an-import-hook).\n\n```python\n# hello.py\n# coding: jsx\nfrom pyjsx import jsx\n\ndef hello():\n print(<h1>Hello, world!</h1>)\n```\n\n```python\n# main.py\nfrom pyjsx import auto_setup\n\nfrom hello import hello\n\nhello()\n```\n\n```sh\n$ python main.py\n<h1>Hello, word!</h1>\n```\n\nEach file containing JSX must contain two things:\n\n- `# coding: jsx` directive - This tells Python to let our library parse the\n file first.\n- `from pyjsx import jsx` import. PyJSX transpiles JSX into `jsx(...)` calls so\n it must be in scope.\n\nTo run a file containing JSX, the `jsx` codec must be registered first which can\nbe done with `from pyjsx import auto_setup`. This must occur before importing\nany other file containing JSX.\n\n## Minimal example (using an import hook)\n\n> [!TIP]\n> There are more examples available in the [examples folder](examples).\n\n```python\n# hello.px\nfrom pyjsx import jsx\n\ndef hello():\n print(<h1>Hello, world!</h1>)\n```\n\n```python\n# main.py\nfrom pyjsx import auto_setup\n\nfrom hello import hello\n\nhello()\n```\n\n```sh\n$ python main.py\n<h1>Hello, word!</h1>\n```\n\nEach file containing JSX must contain two things:\n\n- The file extension must be `.px`\n- `from pyjsx import jsx` import. PyJSX transpiles JSX into `jsx(...)` calls so\n it must be in scope.\n\nTo be able to import `.px`, the import hook must be registered first which can\nbe done with `from pyjsx import auto_setup` (same as for the codec version). This must occur before importing any other file containing JSX.\n\n## Supported grammar\n\nThe full [JSX grammar](https://facebook.github.io/jsx/) is supported.\nHere are a few examples:\n\n### Normal and self-closing tags\n\n```python\nx = <div></div>\ny = <img />\n```\n\n### Props\n\n```python\n<a href=\"example.com\">Click me!</a>\n<div style={{\"color\": \"red\"}}>This is red</div>\n<span {...props}>Spread operator</span>\n```\n\n### Nested expressions\n\n```python\n<div>\n {[<p>Row: {i}</p> for i in range(10)]}\n</div>\n```\n\n### Fragments\n\n```python\nfragment = (\n <>\n <p>1st paragraph</p>\n <p>2nd paragraph</p>\n </>\n)\n```\n\n### Custom components\n\nA custom component can be any function that takes `**kwargs` and\nreturns JSX or a plain string. The special prop `children` is a list\ncontaining the element's children.\n\n```python\ndef Header(children, **rest):\n return <h1>{children}</h1>\n\nheader = <Header>Title</Header>\nprint(header)\n```\n\n## Prior art\n\nInspired by [packed](https://github.com/michaeljones/packed) and\n[pyxl4](https://github.com/pyxl4/pyxl4).\n",
"bugtrack_url": null,
"license": null,
"summary": "JSX transpiler for Python",
"version": "0.2.0",
"project_urls": {
"Github": "https://github.com/tomasr8/pyjsx",
"Homepage": "https://github.com/tomasr8/pyjsx"
},
"split_keywords": [
"jsx",
" react",
" transpiler"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "0199758f5cf58fc58ea9e9465996a5ec493bb3d66aa03ad8e43b70788988b1cf",
"md5": "899aec12ddf935ad24b60ba5615cb43b",
"sha256": "fc9db6be50c45ebea2b8766d8b01bc0c25f0a6cbcc7a489ea9a6d61f4ba7ab4c"
},
"downloads": -1,
"filename": "python_jsx-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "899aec12ddf935ad24b60ba5615cb43b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<=3.14,>=3.10",
"size": 16581,
"upload_time": "2025-01-26T14:59:15",
"upload_time_iso_8601": "2025-01-26T14:59:15.449709Z",
"url": "https://files.pythonhosted.org/packages/01/99/758f5cf58fc58ea9e9465996a5ec493bb3d66aa03ad8e43b70788988b1cf/python_jsx-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "ac61668cfcfee7d64d4f3d8f239628cbd086bf776b28ada7bdb5ff6115e3663c",
"md5": "3bb6926f2d554645445170f1a9055e36",
"sha256": "87adfb020189b21ba77b2fb1916cc55fceda926306ff428b2b8fa312a5b2250f"
},
"downloads": -1,
"filename": "python_jsx-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "3bb6926f2d554645445170f1a9055e36",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<=3.14,>=3.10",
"size": 42672,
"upload_time": "2025-01-26T14:59:17",
"upload_time_iso_8601": "2025-01-26T14:59:17.209034Z",
"url": "https://files.pythonhosted.org/packages/ac/61/668cfcfee7d64d4f3d8f239628cbd086bf776b28ada7bdb5ff6115e3663c/python_jsx-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-26 14:59:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "tomasr8",
"github_project": "pyjsx",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "python-jsx"
}