Document
Solutions

How to Run Python in HTML Using PyScript (2026 Complete Guide)

Running Python directly inside an HTML file was traditionally not possible without a backend server. Python was mainly used on the server side, while JavaScript handled browser interactions. With the introduction of PyScript, this has changed.

PyScript allows developers to run Python code directly in the browser, inside an HTML file, without setting up servers or APIs. In this updated 2026 guide, you’ll learn how to run Python in HTML using PyScript, with practical examples, charts, supported libraries, and important SEO considerations.

This guide is suitable for beginners, Python developers, data scientists, and anyone curious about Python in the browser.

What Does It Mean to Run Python in HTML?

Running Python in HTML means executing Python code inside a web browser, similar to how JavaScript runs. This is made possible using WebAssembly (WASM), which allows Python to be compiled and executed securely in modern browsers.

Unlike traditional setups:

  • No backend server is required
  • No JavaScript frameworks are mandatory.
  • Python runs on the client side.

What Is PyScript?

PyScript is an open-source framework developed by Anaconda that enables Python execution inside HTML pages.

With PyScript, you can:

  • Write Python code directly in HTML
  • Run Python scripts without a backend.
  • Use popular Python libraries like NumPy, pandas, and matplotlib
  • Build interactive browser-based Python applications.

PyScript works using Pyodide, a WebAssembly-based Python runtime, making Python usable in modern browsers.

Important Things About PyScript

  • PyScript allows embedding Python code directly into HTML files.
  • Everything runs inside the browser.
  • No additional environment setup is required.
  • Many popular Python libraries are supported.
  • PyScript uses components like py-script, py-config, and browser-based execution.

In 2026, PyScript has become more stable and is widely used for demos, dashboards, and educational tools.

How PyScript Works Behind the Scenes

PyScript relies on:

  • WebAssembly (WASM) for browser execution
  • Pyodide to run Python
  • Browser sandboxing for security.

When the page loads, the Python runtime is initialized, and Python code is executed just like JavaScript — but using Python syntax.

How to Run Python in HTML Using PyScript

Step 1: Create an HTML File

Create a file named index.html and add the following code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Run Python in HTML</title>

  <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css">
  <script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>

<h1>Python in HTML Example</h1>

<py-script>
print("Hello, Python from HTML!")
</py-script>

</body>
</html>

Step 2: Open the File in a browser.

Open the file in a modern browser such as Chrome, Edge, or Firefox.
You will see the output printed directly on the web page.

Printing Current Date and Time Using Python

You can also use Python modules inside HTML.

<py-script>
from datetime import datetime
print("Current Date and Time:", datetime.now())
</py-script>

This prints the current system date and time inside the browser.

See also  Integrate Sign-in with Apple ID to Create an Account for a Third-Party App

Using Python Libraries in PyScript

One of PyScript’s biggest advantages is its ability to use Python libraries.

Example: Using NumPy

<py-config>
packages = ["numpy"]
</py-config>

<py-script>
import numpy as np
numbers = np.array([1, 2, 3, 4])
print(numbers * 2)
</py-script>

Commonly supported libraries include:

  • NumPy
  • pandas
  • matplotlib
  • sympy
  • Bokeh (with limitations)

Creating Charts in HTML Using Python (Bokeh Example)

PyScript can be combined with visualization libraries like Bokeh to generate charts directly in HTML.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Bokeh Chart with PyScript</title>

  <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css">
  <script defer src="https://pyscript.net/latest/pyscript.js"></script>

  <py-config>
    packages = ["bokeh"]
  </py-config>
</head>
<body>

<h2>Bokeh Chart Using Python in HTML</h2>
<div id="chart"></div>

<py-script>
import json
from js import Bokeh, JSON
from bokeh.plotting import figure
from bokeh.embed import json_item

fruits = ['Apple', 'Banana', 'Mango', 'Orange']
counts = [10, 6, 8, 4]

p = figure(x_range=fruits, height=350, title="Fruit Count")
p.vbar(x=fruits, top=counts, width=0.9)

item = json_item(p, "chart")
Bokeh.embed.embed_item(JSON.parse(json.dumps(item)))
</py-script>

</body>
</html>

This example demonstrates how Python can be used for data visualization directly inside an HTML page.

Why Use PyScript in 2026?

PyScript is best suited for:

  • Interactive demos
  • Educational tools
  • Data visualization dashboards
  • Rapid prototyping
  • Python learning environments

It allows Python developers to create browser-based experiences without learning JavaScript.

PyScript vs JavaScript

FeaturePyScriptJavaScript
LanguagePythonJavaScript
Runs in BrowserYesYes
Backend RequiredNoNo
PerformanceModerateHigh
SEO-Friendly ContentLimitedFull
Best Use CaseDemos & learningProduction apps
PyScript vs JavaScript

Limitations of PyScript

Before using PyScript, consider the following:

  • Slower than JavaScript
  • Larger initial load size
  • Limited browser API access
  • Not ideal for large production websites

PyScript should be used intentionally rather than as a full replacement for JavaScript.

SEO Considerations When Using PyScript

From an SEO perspective:

  • Search engines primarily index static HTML content
  • Content rendered via PyScript may not be indexed.
  • Important SEO text should remain in HTML.
  • PyScript is best used for interactive enhancements.

Avoid relying on PyScript for critical content that must rank in search engines.

Best Practices for Running Python in HTML

  • Keep Python code minimal.
  • Avoid loading large libraries unnecessarily.
  • Provide fallback content where possible.
  • Test performance on mobile devices
  • Use PyScript only where it adds real value.

Key Advantages of Python Development

Python is one of the most versatile and widely used programming languages, supporting everything from web development to data science and automation. Its simplicity, flexibility, and powerful ecosystem make it a preferred choice for modern application development including browser-based execution using technologies like PyScript.

Key Advantages of Python Programming

Extensive and Rich Standard Library
Python offers a vast standard library that reduces development time by providing built-in support for file handling, data processing, networking, and testing.

See also  Woocommerce vs Shopify vs Custom eCommerce: Which is the Best for You?

Wide Range of Application Development
Python is commonly used for:

Strong Automation Capabilities
Python excels in automation using tools such as Selenium, PyAutoGUI, and BeautifulSoup, making it ideal for testing, scraping, and workflow automation.

Growing Frontend & Browser Support
With modern tools like PyScript and WebAssembly, Python can now run directly inside HTML files, opening new possibilities for frontend experimentation and interactive web applications without JavaScript-heavy logic.

Python Programming for Frontend and API Integration

Python integrates seamlessly with backend systems, APIs, mobile applications, and frontend technologies. Python-based APIs can communicate with multiple platforms, making it a strong choice for scalable and modular architectures.

Backend Technologies Compatible with Python

PHP

PHP is a widely used server-side scripting language for building dynamic web pages. Python APIs can easily integrate with PHP-based applications via RESTful services.

.NET

.NET is an open-source development platform for building enterprise-grade applications across desktop, web, and mobile. Python is often used alongside .NET systems for automation, data processing, and microservices.

Node.js

Node.js enables server-side JavaScript execution using the V8 engine. Python APIs frequently work with Node.js-based frontends or backend services through API communication.

Hire Dedicated Developer

Frontend Technologies Supported with Python APIs

React.js

React is a popular JavaScript library for building user interfaces. Python-powered APIs are commonly used as backend services for React applications.

See also  Top 10 Features of Video Conferencing App You Should Know

Angular

Angular is a robust frontend framework maintained by Google, widely used for building scalable single-page applications (SPAs).

Vue.js

Vue.js is a lightweight JavaScript framework following the MVVM architecture, often paired with Python APIs for fast and responsive frontend applications.

Mobile Technologies Supported by Python-Based Backends

1) React Native

React Native enables cross-platform mobile app development using a single codebase. Python APIs are frequently used as backend services for React Native apps.

2) Ionic

Ionic is a cross-platform UI toolkit for building mobile, web, and desktop applications using web technologies.

3) iOS

iOS application development targets Apple devices such as iPhone and iPad. Python is commonly used on the backend for API services supporting iOS apps.

4) Android

Android app development uses Java, Kotlin, or C++. Python-based backend services often power Android applications via REST APIs.

5) Flutter

Flutter is Google’s open-source framework for building native apps across mobile, web, and desktop platforms using a single codebase, frequently supported by Python backends.

Databases Supported by Python Programming

Python works with nearly all modern database systems, including:

MySQL

An open-source relational database widely used in web and enterprise applications.

SQL Databases

Python integrates with SQL-based systems for querying, managing, and analyzing structured data across industries.

PostgreSQL

PostgreSQL supports advanced SQL features and both relational and non-relational data types, making it ideal for complex applications.

MongoDB

MongoDB is a NoSQL database that stores data in a document-based format, commonly used in agile and scalable environments.

Common Use Cases of Python Programming

Python is widely adopted across industries for tasks such as:

  • Building eCommerce platforms, CMSs, and social media applications
  • Developing APIs and RESTful web services
  • Data analysis and visualization in finance, healthcare, travel, and marketing
  • Predictive analytics and machine learning solutions
  • Web scraping and automated data collection
  • DevOps automation and infrastructure management
  • Cloud resource management on AWS, Google Cloud, and Azure

Expertise & Real-World Experience with Python Development

At OneClick IT Solution, we work extensively with Python across web development, API architecture, automation, and data-driven applications. Our development team has hands-on experience building scalable Python solutions that integrate seamlessly with modern frontend frameworks, mobile applications, and cloud platforms.

We actively experiment with emerging technologies such as PyScript, WebAssembly, and browser-based Python execution to evaluate their real-world usability, performance, and security implications. This allows us to provide practical insights—not just theoretical explanations—based on actual development experience.

Our Python developers follow industry best practices for:

  • Secure API development
  • Performance optimization
  • Scalable backend architecture
  • Frontend and browser-based integrations

While tools like PyScript are still evolving, our team continuously tests and monitors their progress to understand where they fit best in modern web development. We believe in sharing transparent, experience-backed knowledge to help developers and businesses make informed technical decisions.

Conclusion

PyScript has made it possible to run Python directly in HTML without a backend server. In 2026, it is a powerful tool for learning, visualization, and interactive demos. While it is not a replacement for JavaScript in production environments, PyScript opens new possibilities for Python developers on the web.

As PyScript continues to mature, we can expect improved performance, stronger security controls, and broader browser support. If you’re exploring new ways to bring Python into the browser, PyScript is definitely worth watching.

Frequently Asked Questions (FAQs)

Can Python run directly in a browser?

Yes. Using WebAssembly and PyScript, Python can now run directly in modern web browsers.

Is PyScript good for production websites?

PyScript is best for demos, dashboards, and learning tools. JavaScript is still recommended for large-scale production apps.

Does PyScript affect SEO?

Yes, if important content depends on it. Keep SEO-critical content in static HTML.

Can I use pandas with PyScript?

Yes, pandas is supported, but large datasets may impact performance.

lets start your project

Related Articles