Vuejs runner, with filesystem, and allowing python extension (e.g., to leverage numpy)
Project description
If you're looking for "Vuejs-python that brings the concepts of vuejs to Python", see our V0 branch (and readme, and V0.* on pypi).
The goal of vuejs-python (starting from V1) is to
- easily run standalone Vue.js components / micro-apps,
- give them access to the working directory,
- allow (unsafe) extensions to be written in Python (including numpy, local resource access, etc)
Installation
pip install vuejspython
Usage
vjspy [--trust-python] [--port=...] [--host=...] myfile.vue more arbitrary parameters
You can run the bundled tools using their : prefixed names instead of the vue file.
These files are in https://github.com/twitwi/vuejs-python/tree/main/vuejspython/builtin
Here are some example usage, that can be followed as a tutorial:
vjspy :create-demo-files demo
vjspy :view-file demo/file1.txt
vjspy :edit-file demo/file1.txt
vjspy --trust-python :rotate-files demo/file*.txt
vjspy :toggle-exam demo/exam/*
# hosting the current folder with a video player
vjspy :serve-videos
Snippets
HTML head
To add something in the HTML head (change title, icon, load library, etc):
<template>
<add-in-head>
<title>View File</title>
<!-- an SVG icon emoji -->
<link rel="icon" type="image/svg+xml"
href="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2016%2016'%3E%3Ctext%20style='filter:hue-rotate(60deg)'%20x='0'%20y='14'%3E👍%3C/text%3E%3C/svg%3E" />
</add-in-head>
...
</template>
Accessing Vue
To import elements from the bundled Vue (you can remove lang="ts" to use plain js, and setup to use a traditional component writing):
<script setup lang="ts">
import { ref, computed } from "#vue"
...
</script>
Accessing files
To use the custom filesystem API (asynchronously):
<script...
const { fs } = window.VueRunner
const content = await fs.readFile('path/to/file')
await fs.writeFile('path/to/file', 'hello content')
await fs.deleteFile('path/to/file')
const allFilesRecursively = (await fs.listFiles()).files
It allows only access to files in the folder where the program has been started (Warning: with --trust-python, this limitation can be worked around easily).
Accessing command line parameters
<script...
const { args } = window.VueRunner
// NB: starts at index 0, no parameters ⇒ args==[]
alert(JSON.stringify(args))
Adding Python code
This requires the program to be launched with --trust-python.
You can add python code in a script element and FastAPI:
<script...
alert(await((await fetch('/.path')).text()))
</script>
<script lang="python">
@app.get("/.path")
def get_path():
import sys
return sys.path
</script>
See also the rotate-files example that uses command line arguments (in python) too.
Handling url hash
<script...
const { onHash, setHash } = window.VueRunner
onHash((h) => {
// also triggers on first load (with empty hash or the hash from the initial URL)
if (h !== '') {
alert('you changed the address to '+h)
}
})
function showAbout() {
...
setHash('about')
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vuejspython-1.0.6.tar.gz.
File metadata
- Download URL: vuejspython-1.0.6.tar.gz
- Upload date:
- Size: 580.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a72b59d4853de8339722781ba5530d163b36977c99bedabcfb9e05f6f4284285
|
|
| MD5 |
ca544e61d43974ad2d7acf47787d6569
|
|
| BLAKE2b-256 |
69ebd0b7f7b163cfc304a1fedbc03baa6c7724f2d2f3106fe5df7e0298943db9
|
File details
Details for the file vuejspython-1.0.6-py3-none-any.whl.
File metadata
- Download URL: vuejspython-1.0.6-py3-none-any.whl
- Upload date:
- Size: 729.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28d4168097078ea3c46012ce280877e2594358860710d371d3ec41e4136a14f8
|
|
| MD5 |
55776718a1a54a6c638421033173c6d7
|
|
| BLAKE2b-256 |
5c71e39a7a691a7ea43d67b1c89abb1cf97e2194fba501384ed4f70b7ad5f573
|