Skip to main content

Use web resources the pythonic way, import JavaScript modules like you do with Python modules.

Project description

whatchamacallit

Use web resources the pythonic way. Import Javascript modules like you do with Python modules. Specify Javascript modules, HTML, CSS as bare URLs and rewrite on the fly.

Example

(A) First install the desired package

pip install gridchen

(B) Then from HTML/JavaScript

<!DOCTYPE html>
<h1>Hello World</h1>
<script type="module">
    import * as utils from "gridchen/utils.js";
    const tm = utils.createTransactionManager();
</script>

(C) Configure the import map

spec_mapping: Dict[str, str] = {'gridchen/': '/gridchen/'}

(D) Run one of the example servers (FastAPI or Flask)

Working

Ultimately, the import * as utils from "gridchen/utils.js" must be mapped to its physical location, for example /C/projects/myproject/venv/Lib/site-packages/gridchen/utils.js. This is done in two steps.

Remap bare import specifier

The import * as utils from "gridchen/utils.js" is not valid JavaScript. So at HTML/JavaScript load time the import is remapped to import * as utils from "/gridchen/utils.js"

Route resources to package modules

When the server now gets the request for /gridchen/utils.js, then it needs to resolve to the package gridchen and serve its resource utils.js.

Configure Poetry

poetry publish

Build

poetry build

Publishing to PyPI

poetry publish

Previous Work

Bundlers:

Unpkg.com, rollup, webpack, babel, pika, assetgraph, Browserify, gulp, JSPM

In Place:

snowflake, Open Web Components, browser sync, es-module-shims

See

http://dplatz.de/blog/2019/es6-bare-imports.html

https://jakearchibald.com/2017/es-modules-in-browsers/

https://medium.com/@dmnsgn/in-2020-go-bundler-free-eb29c1f05fc9

https://wicg.github.io/import-maps/

https://medium.com/@dmnsgn/es-modules-in-the-browser-almost-now-3638ffafdc68

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whatchamacallit-0.0.3.tar.gz (6.3 kB view hashes)

Uploaded Source

Built Distribution

whatchamacallit-0.0.3-py3-none-any.whl (7.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page