Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/keller-mark/esbuild-py

Python bindings to the golang esbuild Transform API
https://github.com/keller-mark/esbuild-py

Last synced: about 2 months ago
JSON representation

Python bindings to the golang esbuild Transform API

Awesome Lists containing this project

README

        

# esbuild-py

[![PyPI](https://img.shields.io/pypi/v/esbuild_py)](https://pypi.org/project/esbuild_py)
[![Open In Colab - minimal](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/gist/keller-mark/0f3d810fcc2a774ba5ce9bee6fa16007)
[![Open In Colab - dynamic-importmap](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/gist/keller-mark/8d8f13378e73cea8de122385bf34d695)

Python bindings to the [esbuild](https://github.com/evanw/esbuild) [Transform API](https://pkg.go.dev/github.com/evanw/[email protected]/pkg/api#hdr-Transform_API).
## Installation

```py
pip install esbuild_py
```

## Usage

```python
from esbuild_py import transform

jsx = """
import * as React from 'react'
import * as ReactDOM from 'react-dom'

ReactDOM.render(

Hello, world!

,
document.getElementById('root')
);
"""

print(transform(jsx))
```

## API

### `transform`

Parameters:
- `jsx` (`str`) - The JSX string to be transformed.

Returns: `str` - The transformed JS as a string.

## Development

### Setup

Create conda environment

```sh
conda create -n esbuild-py python=3.11
```

- Install go v1.20.12 from https://go.dev/dl/

### Build

```sh
conda activate esbuild-py
go get github.com/keller-mark/esbuild-py
# go build -buildmode=c-shared -o _esbuild.so
```

### Develop

Build python package and install in editable mode

```sh
python setup.py bdist_wheel
python setup.py sdist
pip install -e .
```

### Publish

Increment the version in `pyproject.toml`.
The [cibuildwheel](https://github.com/pypa/cibuildwheel) GH action will build wheels for a matrix of Python versions, OS, and architectures.
Then, GH actions will publish to PyPI.

## Resources

- https://github.com/ardanlabs/python-go/tree/master/pyext
- https://pkg.go.dev/github.com/evanw/[email protected]/pkg/api#hdr-Transform_API
- https://github.com/evanw/esbuild/blob/main/.github/workflows/ci.yml