Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 01297cf

Browse files
kmehtzpao
authored andcommitted
Added PyReact blog post.
1 parent 89437e6 commit 01297cf

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: "Use React and JSX in Python Applications"
3+
layout: post
4+
author: Kunal Mehta
5+
---
6+
7+
Today we're happy to announce the initial release of [PyReact](https://github.com/facebook/react-python), which makes it easier to use React and JSX in your Python applications. It's designed to provide an API to transform your JSX files into JavaScript, as well as provide access to the latest React source files.
8+
9+
## Usage
10+
11+
Transform your JSX files via the provided `jsx` module:
12+
13+
```python
14+
from react import jsx
15+
16+
# For multiple paths, use the JSXTransformer class.
17+
transformer = jsx.JSXTransformer()
18+
for jsx_path, js_path in my_paths:
19+
transformer.transform(jsx_path, js_path)
20+
21+
# For a single file, you can use a shortcut method.
22+
jsx.transform('path/to/input/file.jsx', 'path/to/output/file.js')
23+
```
24+
25+
For full paths to React files, use the `source` module:
26+
27+
```python
28+
from react import source
29+
30+
# path_for raises IOError if the file doesn't exist.
31+
react_js = source.path_for('react.min.js')
32+
```
33+
34+
## Django
35+
36+
PyReact includes a JSX compiler for [django-pipeline](https://github.com/cyberdelia/django-pipeline). Add it to your project's pipeline settings like this:
37+
38+
```python
39+
PIPELINE_COMPILERS = (
40+
'react.utils.pipeline.JSXCompiler',
41+
)
42+
```
43+
44+
## Installation
45+
46+
PyReact is hosted on PyPI, and can be installed with `pip`:
47+
48+
$ pip install PyReact
49+
50+
Alternatively, add it into your `requirements` file:
51+
52+
PyReact==0.1.1
53+
54+
**Dependencies**: PyReact uses [PyExecJS](https://github.com/doloopwhile/PyExecJS) to execute the bundled React code, which requires that a JS runtime environment is installed on your machine. We don't explicitly set a dependency on a runtime environment; Mac OS X comes bundled with one. If you're on a different platform, we recommend [PyV8](https://code.google.com/p/pyv8/).
55+
56+
For the initial release, we've only tested on Python 2.7. Look out for support for Python 3 in the future, and if you see anything that can be improved, we welcome your [contributions](https://github.com/facebook/react-python/blob/master/CONTRIBUTING.md)!

0 commit comments

Comments
 (0)