파이스크립트(PyScript)란?
- 간단히 요약하면 HTML 에서 JavaScript를 사용하듯 Python을 사용할 수 있음
장점
- 특별한 플러그인 없이 Python 코드를 html에서 실행 가능
- matplotlib, numpy, pandas, scikit-learn 같은 모듈 지원
- 사용자 정의 클래스 로드 가능
- Python과 Javascript 개체 및 네임스페이스 간의 양방향 통신 가능
- 주피터 노트북 같은 대화형 경험을 할 수 있는 위젯 생성 가능
- 버튼, 컨테이너, 텍스트 상자 등과 같은 UI 구성요소 지원
- 표준 HTML 지원
단점
- 아직 실험적 단계
- 아직까지 공식적으로 지원되는 라이브러리는 제한적, 예를 들어 Tensorflow같은 라이브러리는 불가
- 파이스크립트를 적용한 HTML 페이지는 로딩되는데 시간이 오래 걸림
- 공식 페이지에서도 아직까진 상업용 프로젝트에는 사용하지 말 것을 권고
* 테스트 중 아직 지원 안되는 라이브러리 업데이트
- bs4, requests
Sample
- Html 파일 만으로 Hello World 출력
- head 태그에 css와 js파일을 로드(필수)
- 바디에 <py-script> 태그를 생성한 뒤 파이썬 코드 작성
* 실행할 파이썬 코드
text = "Hello World"
print(text)
* pyscript를 적용한 html
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>PyScript Hello World</title>
<!-- 파이스크립트를 실행하기 위해 head 부분에 css와 js 파일을 로드-->
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body>
<div>
<!-- 파이썬 코드임을 명시하는 py-script 태그 사용-->
<py-script>
text = "Hello World"
print(text)
</py-script>
</div>
</body>
</html>
* 실행 화면
PyScript 공식 페이지
Pyscript.net
Run Python code in your HTML.
pyscript.net
PyScript 예제 링크
- https://pyscript.net/examples/
PyScript demo
PyScript demos Basic examples A static demo of the tag A dynamic demo of the tag A Python REPL (Read Eval Print Loop). A Python REPL (Read Eval Print Loop) with slightly better formatting. Demo showing how would a Simple TODO App would look like in PyScrip
pyscript.net
2022.05.27 - [PyScript] - PyScript #html에 텍스트 입력 후 출력
PyScript #html에 텍스트 입력 후 출력
html에 텍스트 입력 후 출력 1. 기본 html 생성 <!DOCTYPE html> PyScript input&output 2. 에 pyscript.js 및 사용할 css 로드 - 삽입 후 코드 <!DOCTYPE html> PyScript input&output 3. 에 텍스트를 출력할..
sputnik-kr.tistory.com
'PyScript' 카테고리의 다른 글
PyScript #html에 텍스트 입력 후 출력 (1) | 2022.05.27 |
---|