npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

io-repl

v0.1.1

Published

A mini Python REPL for the browser

Downloads

4

Readme

Io

License npm Repo Size Docs

Io is web component library for running Python codeblocks in the browser. Its core element is <io-repl>, a mini Python REPL powered by Pyodide.

Io is a lightweight and highly experimental library. It's just for fun and shouldn't be used for anything serious. If you're looking for a similar library to use in your projects, consider using PyScript instead.

Quickasrt

Add the <io-repl> script to the head of your HTML document:

<script type='module' src='https://www.unpkg.com/io-repl/io-repl.js'></script>

Add the following rule to your stylesheet to prevent the component from being displayed until its ready:

io-repl:not(:defined) {
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
}

Use <io-repl> in your HTML document:

<io-repl>import this</io-repl>

Installation

Linking to a CDN

<script type='module' src='https://www.unpkg.com/io-repl/io-repl.js'></script>

Installing from npm

npm i io-repl

Building from source

  1. Clone this repository

    git clone https://github.com/codesue/io.git
  2. Navigate to the project's directory

    cd io
  3. Install dependencies

    npm i

Usage

Importing the component in a module

import 'io-repl';

Adding a REPL to your HTML document

Adding an empty REPL:

<io-repl></io-repl>

Adding default code to the REPL:

<io-repl>print('Hello, world!')</io-repl>

Adding default code that relies on indentation to the REPL:

<io-repl>
  def greet():
    print('Hello, there!')

  greet()
<io-repl>

Customizing the REPL

You can customize the REPL using the following attributes:

  • button-label (string): The text to display as the run button's label.
  • disable-button (boolean): Whether to disable and hide the run button.
  • disable-input (boolean): Whether to disable editing input code.
  • execute (boolean): Whether to execute the code when the component is rendered.
  • pyodide-src (string): The path to a pyodide module to import. If not provided, defaults to https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.js.
  • src (string): The path to a file containing Python code. Its text will be set as the code input of the REPL, taking precedent over any text inside the <io-repl></io-repl> tags.

Here's an example of how to do this:

<io-repl execute disable-input button-label='Play' pyodide-src='https://path/to/pyodide.js'>
<io-repl>

Styling with CSS

Preventing FOUC (flash of unstyled content)

Add the following rules to your stylesheet:

io-repl:not(:defined) {
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
}

Customizing component styles

You can change the style of the <io-repl> element directly:

io-repl {
  background: #c9cdee;
  padding: 1em;
  border-radius: 0.25em;
}

You can change the style of its nested elements using css variables defined in the elements <style> tag:

io-repl {
  --input-border-radius: 0.25em;;
  --button-border-radius: 0.25em;;
  --button-font-family: monospace;
  --button-padding: 0.25em 0.5em;
  --button-margin: 0;
}

Alternatively, you can use the elements' part attribute:

io-repl::part(button) {
  border-radius: 0.25em;
}

Parts include label, button, input, input-container, and output.

Developing the library

Running the local demo with web-dev-server

To run a local development server that serves the basic demo located in index.html, run:

npm start

The website will be available at http://localhost:8000/.

Testing with Web Test Runner

To execute a single test, run:

npm run test

To run the tests in interactive watch mode, run:

npm run test:watch

Linting and formatting

To scan the project for linting and formatting errors, run

npm run lint

To automatically fix linting and formatting errors, run

npm run format

Contributing

Currently, this project does not accept external contributions.

License

Copyright © 2023 Suzen Fylke. Distributed under the MIT License.

Acknowledgements

This project was scaffolded with open-wc's web component generator.

It forks PyScript's ltrim function to dedent code input, and parts of its design are heavily influenced by the design of PyScript's web components. PyScript is licensed under the Apache 2.0 License.