title: How to embed a language like JSX into a python script?
body: <p>At our company we love to write django driven applications and we also love to use react. Recently we thought about writing a component based templating engine for python where templates can be written as react-like components using JSX.</p>
  
  <p>Ideally it should be possible to embed JSX into the python code so that you can write components like this:</p>
  
  <p>In <code>header.pyx</code>:</p>
  
  <pre><code>import PyReact
  from my_awsome_project.components import Logo, Link
  
  
  def Header(context):
      page_title = context.get('page_title')
      links = context.get('links')
  
      return (
          &lt;div&gt;
              &lt;Logo /&gt; 
              {page_title}
              &lt;ul&gt;
                  {[&lt;Link href={link.url}&gt;{link.title}&lt;/Link&gt; for link in links]}
              &lt;/ul&gt;
          &lt;/div&gt;
      )
  </code></pre>
  
  <p>This would of course require to transpile the file first to get valid python code. It would transpile to something somewhat similar as that:</p>
  
  <pre><code>import PyReact
  from my_awsome_project.components import Logo, Link
  
  
  def Header(context):
      page_title = context.get('page_title')
      links = context.get('links')
  
      return (
          PyReact.createComponent('div', context, [
              PyReact.createComponent(Logo),
              page_title,
              PyReact.createComponent('ul', context, [
                   [
                        PyReact.createComponent(Link, {'href': link.url}, link.title)
                        for link in links
                   ]
              ]),
          ])
      )
  </code></pre>
  
  <p>The question is: How would I approach writing such a transpiler?</p>
  
  <p>Also we thought about instead of embedding JSX directly into the python code directly we could return a string containing the JSX that gets parsed independently. Would that be a better/easier approach?</p>