{"componentChunkName":"component---src-templates-blog-js","path":"/blog/2013/08/19/use-react-and-jsx-in-python-applications.html","result":{"data":{"markdownRemark":{"html":"<p>Today we’re happy to announce the initial release of <a href=\"https://github.com/facebook/react-python\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">PyReact</a>, 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.</p>\n<h2 id=\"usage\"><a href=\"#usage\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Usage </h2>\n<p>Transform your JSX files via the provided <code class=\"gatsby-code-text\">jsx</code> module:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"gatsby-code-python\"><code class=\"gatsby-code-python\"><span class=\"token keyword\">from</span> react <span class=\"token keyword\">import</span> jsx\n\n<span class=\"token comment\"># For multiple paths, use the JSXTransformer class.</span>\ntransformer <span class=\"token operator\">=</span> jsx<span class=\"token punctuation\">.</span>JSXTransformer<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> jsx_path<span class=\"token punctuation\">,</span> js_path <span class=\"token keyword\">in</span> my_paths<span class=\"token punctuation\">:</span>\n    transformer<span class=\"token punctuation\">.</span>transform<span class=\"token punctuation\">(</span>jsx_path<span class=\"token punctuation\">,</span> js_path<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># For a single file, you can use a shortcut method.</span>\njsx<span class=\"token punctuation\">.</span>transform<span class=\"token punctuation\">(</span><span class=\"token string\">'path/to/input/file.jsx'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'path/to/output/file.js'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>For full paths to React files, use the <code class=\"gatsby-code-text\">source</code> module:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"gatsby-code-python\"><code class=\"gatsby-code-python\"><span class=\"token keyword\">from</span> react <span class=\"token keyword\">import</span> source\n\n<span class=\"token comment\"># path_for raises IOError if the file doesn't exist.</span>\nreact_js <span class=\"token operator\">=</span> source<span class=\"token punctuation\">.</span>path_for<span class=\"token punctuation\">(</span><span class=\"token string\">'react.min.js'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h2 id=\"django\"><a href=\"#django\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Django </h2>\n<p>PyReact includes a JSX compiler for <a href=\"https://github.com/cyberdelia/django-pipeline\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">django-pipeline</a>. Add it to your project’s pipeline settings like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"gatsby-code-python\"><code class=\"gatsby-code-python\">PIPELINE_COMPILERS <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>\n  <span class=\"token string\">'react.utils.pipeline.JSXCompiler'</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">)</span></code></pre></div>\n<h2 id=\"installation\"><a href=\"#installation\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Installation </h2>\n<p>PyReact is hosted on PyPI, and can be installed with <code class=\"gatsby-code-text\">pip</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"gatsby-code-text\"><code class=\"gatsby-code-text\">$ pip install PyReact</code></pre></div>\n<p>Alternatively, add it into your <code class=\"gatsby-code-text\">requirements</code> file:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"gatsby-code-text\"><code class=\"gatsby-code-text\">PyReact==0.1.1</code></pre></div>\n<p><strong>Dependencies</strong>: PyReact uses <a href=\"https://github.com/doloopwhile/PyExecJS\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">PyExecJS</a> 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 <a href=\"https://code.google.com/p/pyv8/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">PyV8</a>.</p>\n<p>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 <a href=\"https://github.com/facebook/react-python/blob/master/CONTRIBUTING.md\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">contributions</a>!</p>","excerpt":"Today we’re happy to announce the initial release of PyReact, 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. Usage  Transform your JSX files via the provided  module: For full paths to React files, use the  module: Django  PyReact includes a JSX compiler for django-pipeline. Add it to your project’s pipeline settings like this…","frontmatter":{"title":"Use React and JSX in Python Applications","next":null,"prev":null,"author":[{"frontmatter":{"name":"Kunal Mehta","url":"https://github.com/kmeht"}}]},"fields":{"date":"August 19, 2013","path":"content/blog/2013-08-19-use-react-and-jsx-in-python-applications.md","slug":"/blog/2013/08/19/use-react-and-jsx-in-python-applications.html"}},"allMarkdownRemark":{"edges":[{"node":{"frontmatter":{"title":"Introducing the New JSX Transform"},"fields":{"slug":"/blog/2020/09/22/introducing-the-new-jsx-transform.html"}}},{"node":{"frontmatter":{"title":"React v17.0 Release Candidate: No New Features"},"fields":{"slug":"/blog/2020/08/10/react-v17-rc.html"}}},{"node":{"frontmatter":{"title":"React v16.13.0"},"fields":{"slug":"/blog/2020/02/26/react-v16.13.0.html"}}},{"node":{"frontmatter":{"title":"Building Great User Experiences with Concurrent Mode and Suspense"},"fields":{"slug":"/blog/2019/11/06/building-great-user-experiences-with-concurrent-mode-and-suspense.html"}}},{"node":{"frontmatter":{"title":"Preparing for the Future with React Prereleases"},"fields":{"slug":"/blog/2019/10/22/react-release-channels.html"}}},{"node":{"frontmatter":{"title":"Introducing the New React DevTools"},"fields":{"slug":"/blog/2019/08/15/new-react-devtools.html"}}},{"node":{"frontmatter":{"title":"React v16.9.0 and the Roadmap Update"},"fields":{"slug":"/blog/2019/08/08/react-v16.9.0.html"}}},{"node":{"frontmatter":{"title":"Is React Translated Yet? ¡Sí! Sim! はい！"},"fields":{"slug":"/blog/2019/02/23/is-react-translated-yet.html"}}},{"node":{"frontmatter":{"title":"React v16.8: The One With Hooks"},"fields":{"slug":"/blog/2019/02/06/react-v16.8.0.html"}}},{"node":{"frontmatter":{"title":"React v16.7: No, This Is Not the One With Hooks"},"fields":{"slug":"/blog/2018/12/19/react-v-16-7.html"}}}]}},"pageContext":{"slug":"/blog/2013/08/19/use-react-and-jsx-in-python-applications.html"}},"staticQueryHashes":[]}