Ever-Improving Python Points To A Future Of Greater Functionality

Python course in Noida

Today, there’s no getting away from Python when it comes to web development. The programming language has emerged as one of the most popular of its kind. In fact, in 2021, Stack Overflow found that as much as two-thirds of the developers currently using the language feel very positively about Python and plan to continue doing so. Now, as more innovations promise even greater functionality, it seems clear that Python will cement itself as a global standard in the future.

Python acts as a general-purpose programming language that can be used for virtually any kind of software imaginable. It can be used to create websites, AI constructs, faster servers, business software and much more.

As we can see from the chart above, the majority of respondents in the field of data science prefer to use Python as their primary choice of programming language. This is largely down to the strong levels of security and adaptability that the language can boast in comparison to major rivals like SQL and R.

With the recent PyCon 2022 suggestion that Python developers may soon be capable of running code within their own browsers, its popularity may become strong enough to become an industry standard in a future that’s punctuated by Web3.0 potential.

Let’s take a deeper look at what the coming months could hold in terms of upcoming innovations for Python developers and businesses looking to adopt Python frameworks to bolster their online presence:

Browser-Based Python

One of the biggest drawbacks of Python has been that it’s impossible for users to run its code in a browser. Despite its popularity, Python falls short in comparison to another widely used programming language, JavaScript.

However, this may soon change. At PyCon 2022, which is an annual conference for the language’s more passionate users, developers have claimed that it may soon be possible to run the code within browsers.

PyCon 2022 was the first incarnation of the annual event, which due to Covid-19 reasons has been unable to reconvene since 2019. In this three year gap, it appears that a flurry of new developments have been unveiled that could help to ensure Python’s position as a developer favorite remains.

When it comes to browser compatibility, Python hasn’t supported compilation to the WebAssembly (Wasm) runtime, which acts as a key IC3 web application that utilizes code written in Rust, C, C++, and is capable of converting into a binary format. This helps web-based applications to behave more like desktop applications when outside the browser.

"Python can be run on many platforms: Linux, Windows, Apple (News - Alert) Macs, microcomputers, and even Android devices. But it's a widely known fact that, if you want code to run in a browser, Python is simply no good – you'll just have to turn to JavaScript," suggested The Python Software Foundation in a recent blog post. "Now, however, that may be about to change."

CPython developers Christian Heimes and Ethan Smith shared their findings at PyCon 2022, specifying that they have enabled CPython’s main branch to compile to WebAssembly. CPython is the abbreviated name for Core Python, and is the reference implementation that other Python languages derive from.

Such a development will be a massive step for the adoption of Python’s programming language - particularly as businesses ramp up their online presence ahead of Web3.0. With CPython now cross-compiling to WebAssembly via Emscripten - which is a toolchain compiling projects written in C or C++ to Node.Js or Wasm runtimes - it’s possible for developers to enjoy far greater functionality in their programming.

The Arrival of CPython brings Greater Speeds

CPython is expected to launch in October 2022, and will include a collection of key improvements in terms of performance and support. The fundamental reason for this improved functionality stems from the availability of C Run-time, as well as greater compatibility with C/C++ programming languages.

At PyCon, CPython’s development team confirmed a series of changes that are set to improve the speed of the language.

At this stage, the Microsoft (News - Alert) HotPy project has been lured in by the prospect of operating on CPython to the point where the project is set to embrace the improved incarnation of the language.

Through the utility of a JIT (Just-In-Time) runtime compiler, it’s possible to experience speeds up to a factor of 10 for pure python code. Analytics Insight notes that the beta version of CPython 3.11 is, on average, around 25% faster in benchmark testing. Furthermore, the project has a roadmap for more improvements and additions.

All of these improvements will be music to the ears of business leaders looking to better market themselves in the age of digital transformation. CPython’s greater functionality means that it can be easier for in-house teams to make changes on the fly, or simpler for Python development teams to better communicate and collaborate with clients in real-time.

Today, Python is the world’s best loved programming language, and with upcoming developments that are set to deliver greater functionality and speeds, it’s clear that it’s going to take some beating when it comes to the mechanics of the internet.

Introducing Python For CAD

15 Jun, 2022 By: Andrew G. Roe CAD Programming: Open-source language offers intriguing features for CAD programmers.


Of all the programming options available to CAD programmers, one of the more intriguing is Python. An open-source platform named after the British comedy troupe Monty Python, Python is a high-level, interpreted language, meaning the code is relatively easy to decipher and the development process is often faster than that of other languages.

In this article, we’ll take a brief tour of Python, looking at some key features that might be helpful to CAD programmers. We’ll also look at some of the different flavors, or implementations, of Python. We’ll then circle back and see how to use Python in conjunction with Dynamo, a tool we explored in previous articles. The terminology and nuances can be a bit confusing at first, but hang on through the tour to see what Python has to offer.

Why Learn Python?

As a high-level language, Python uses recognizable English keywords instead of cryptic phrases that only a computer could love. Its formatting is relatively simple, with minimal use of punctuation, curly brackets, and other symbols commonly used in other languages. For both new and experienced programmers, this makes Python fairly easy to learn.

Because it is an interpreted language, Python code does not need to be compiled before running — a considerable time saver during program development. The interpreter can be used interactively, allowing you to see results as you type code.

With high-level data structures such as flexible arrays and dictionaries, Python can be used as an extension language for customizable applications such as AutoCAD and MicroStation. In fact, the extensibility of Python allows you to interact with code written in totally different languages, such as C/C++ or Java. Python also lets you build modules that can be reused in other Python programs.

As an open-source language, Python is free to download, use, and distribute. Documentation is readily available on the Python website, along with a plethora of examples. Other websites and videos scattered across the internet offer additional examples and guidance.

Versions and Implementations

Just as many commercial software vendors offer different versions of their products, various open-source communities have developed different implementations of Python. The standard implementation, CPython, is generally referred to simply as Python. Written in C, as implied by the name, it is considered the baseline implementation, most aligned with Python standards.

IronPython is an implementation of Python based on the .NET runtime. You can load .NET assemblies into IronPython programs using an object-oriented syntax. You can also compile IronPython code into an assembly and run it standalone or invoke it from other languages.

PyPy is a variation developed to improve performance using just-in-time (JIT) compilation. By compiling Python code into machine language behind the scenes, PyPy can achieve significant speed gains on large programs.

For AutoCAD programmers, pyautocad is a Python library geared toward writing ActiveX Automation scripts for AutoCAD. It is helpful for working with coordinates, object iteration and searching, and data import and export. Certain Autodesk products, such as Civil 3D and Revit, also include a built-in version of Python in the Dynamo environment. More on this later.

On the Bentley side, Python developer shells are available for certain vertical applications.  For example, Python-based software development kits (SDKs) are available for LumenRT, Bentley’s visualization and reality modeling software, and PLAXIS, a geotechnical analysis product. The Bentley visualization and geotechnical analysis user communities provide more information.

Several other flavors of Python are also available. The Python Package Index (PyPI) is a repository of various Python implementations.

Installing and Starting Python  

To use Python outside of the Dynamo environment, first install it on your computer. A small fraction of Windows PCs have Python pre-installed, but chances are you will need to download and install it. To check to see if you already have it, enter python in a Command line window. If you see a response from a Python interpreter, you have the version identified in the initial display. If you need to install Python, you can find the latest version on the Python downloads page and follow the instructions to install it.

Once you install Python, you should see it listed on your startup menu, or you can invoke it from the Command line. The Python interpreter does not have a fancy interface, but the shell provides the basic tools to get started.

Syntax Fundamentals  

Before learning how to write code in Python, check out the interactive nature of the interpreter by typing in a mathematical expression, such as 2+2, right after the Command prompt, which is Python displays the answer on the next line.

While Python is a high-level language that uses common English phrases, there are still some rules to follow. We won’t cover them all here, as the website includes thorough documentation, but here are some highlights:

As you’ve seen, you can type a numerical expression and the interpreter writes the value. The mathematical operators +, -, *, and / work just like in most other languages.

Strings, or text, can be enclosed in single quotes (‘Hello’) or double quotes (“Hello”) with the same result.

Lists can be written as a series of comma-separated values between square brackets. For example: Layers = [0, 1, 2, 10]

Functions perform specific actions. For example, the print() function writes the value of the argument(s) enclosed by parentheses.

Methods are functions associated with a particular object. Many built-in data types come with pre-defined methods, and you can also create your own methods.

A variety of logic and flow-control tools are available, such as if, for, and while statements.

Python code can be written with any text editor, though you may benefit by using more enhanced text editors like Visual Studio Code or Notepad++. From the Python shell interface, you can save your code for reuse by clicking File | Save and giving your file a name.

And Now for Something Completely Different Python and Dynamo  

(Did you catch the Monty Python reference in the heading?) With some Python fundamentals covered, we can now turn to what Python has to offer CAD programmers. For AutoCAD programmers, one way to leverage Python code is via the Dynamo environment.

In previous articles, we learned how to use Dynamo to create a line, as well as how to use code blocks to simplify Dynamo scripts. By combining Python and Dynamo, you can combine tools from both environments to build custom applications. Autodesk products aid this process by including a built-in version of Python within Dynamo.

In Civil 3D 2022, both the CPython and the IronPython interpreters are available. This is primarily for compatibility reasons, as CPython is currently in version 3, while IronPython is only available in version 2. The version of Python available in other Autodesk products may vary by version, but the ability to access Python within the Dynamo environment has been a significant step for CAD programmers.

In our first Dynamo article, we demonstrated how to create an AutoCAD line using pre-defined point coordinates. The Dynamo graph looked like this:

Instead of using input nodes for each coordinate value, you can use a Python script to provide the same input for some or all of the nodes. To demonstrate, we’ll establish the Y2 value using Python:

1. Open a Civil 3D (or Revit) drawing and create a Dynamo session similar to the one above. (Refer to the first article for a recap of those steps. If you already worked through that example, you can reuse your script.)

2. In the Search box of the Library pane in Dynamo, type “Python” to access the Python environment. Click Python Script to add this node to your workspace.

3. Double-click in the lower portion of the Python Script node to open the Python Script editor. Notice near the lower-left portion of the window a drop-down showing the two versions of Python available. For this example, we’ll use CPython.

4. The Python Script editor includes numerous lines of boiler-plate code that you can ignore for now. Change the last line to read as follows:

OUT = Y2

5. Just above last line, insert a new line as follows:

Y2 = 76. Connect the output of the Python Script node to the Y-value in the Point.ByCoordinates node. The modified Dynamo graph should look like this:

7. Click Run in the lower-left corner of the Dynamo window to run your script. (You can skip this step if you’re running Dynamo in Automatic mode.) You should see a new line drawn with the Y-value generated by Python.

While this is a greatly simplified example for brevity, you can see how you can use Python to provide additional power to your programming toolbox. With Python’s more robust features such as logic and flow-control, along with Dynamo’s graphic environment for creating programs quickly, the sky is the limit for creating custom applications.

We’ll continue to explore how to use Dynamo, Python, and other tools in future articles. If you have specific ideas for programming topics, feel free to drop us an email.


Wireless MicroPython Programming With Thonny

I’ve been playing with a few MicroPython projects recently on several different embedded platforms, including a couple of ESP32 WiFi modules. There are various ways to program these modules:

Use a serial terminal and ampy (maintained by [devxpy] since being dropped by Adafruit in 2018).

If you use Pycom boards or WiFy firmware, there are the pymakr plugins for Atom and Visual Studio.

If you prefer the command-line like me, there is rshell by one of the top MicroPython contributors.

For over a year, I have been quite happy with rshell until I started working on these wireless nodes. Being lazy, I want to tinker with my ESP32 modules from the sofa, not drag my laptop into the kitchen or balcony to plug up a USB cable. Can’t I work with them wirelessly?

Well, you can use WebREPL. While its functional, it just didn’t strike my fancy for some reason. [Elliot] mentioned in a recent podcast that he’s using telnet to access his wireless nodes, but he’s using esp-link on an ESP8266, which means throwing another chip into the mix.

The Thonny IDE

I had all but given up when by chance I saw this video on the Dronebot Workshop channel about running MicroPython on the new Raspberry Pi Pico boards. Bill was using Thonny, a Python IDE that is popular in the education community. Thonny was introduced in 2015 by Aivar Annamaa of the University of Tartu in Estonia. Thonny was designed to address common issues observed during six years of teaching Python programming classes to beginners. If you read about the project and its development, you’ll see that he’s put a lot of effort into making Thonny, and it shows.

Leaning about Thonny got me curious, and after a little digging I discovered that it has WebREPL support for MicroPython right out-of-the-box. Although this is a new feature and classified as experimental, I found it reasonably stable to use and more than adequate for home lab use.

Installation and Connection

Instructions are clearly given on the project’s website. There is a downloader link at the top of the page for Windows. For Linux and Mac simply doing sudo apt install thonny or brew install thonny was all I needed. If you have a Raspberry Pi, you will find Thonny is pre-installed — version 3.3.3 was found on a recent Pi 4 in my lab. On an older Pi 3 however, Thonny was too old and simply reinstalling it didn’t work for me. Doing a sudo apt update, sudo apt upgrade, and then reinstalling Thonny resulted in the latest version 3.3.6.

For some reason, the Thonny found in the Ubuntu 20.04 and Debian Buster package repositories also weren’t recent enough. Rather than building from source, I used the provided Linux installation script that downloads and installs the latest release.

In order to connect to a module, you will use the Run -> Select interpreter... Menu. Here you pick which type of module to use, and which interface (USB or WebREPL). Note that you have to connect to your module over USB first and make sure that WebREPL is enabled in boot.Py. This is the normal method of enabling WebREPL in general — if your module already has WebREPL setup, you don’t need to change anything. Fill in the WebREPL URL and password — you should connect and be good to go.

Tweaks Thonny Connection Screen

By default, Thonny’s windows are stacked vertically. If you’re using a modern wide-screen monitor, you will probably want to rearrange the windows in Thonny so the editor and shell are side-by-side (see the feature image). This is done by adding ShellView.Location = e to the [view] section of the configuration.Ini file (see here). The e means East, and other compass points like se can be specified as well. For the systems I tested, the configuration file can be found in the following places:

I had no problems using the REPL manually, but I discovered an issue once you start testing self-starting applications with forever loops. If you are not careful, your application’s main loop can prevent you from regaining REPL control. The solution is to make sure your application sleeps for several milliseconds in the main loop. I tested with 100 ms (see here) and was always able to regain control. This shouldn’t be an issue in most home sensor applications, where the module may sleep for tens of minutes between readings.

By default, a Thonny installation doesn’t make itself visible for command line execution. On the computers I tested, you will find the Thonny executable in the following locations:

Raspi /usr/bin/thonny

Ubuntu, Debian (installed via installer script)~/apps/thonny/bin/thonny

Mac/Applications/Thonny.App/Contents/MacOS/thonny

WindowsC:\Users\\AppData\Local\Programs\Thonny\thonny.Exe

Multiple Modules and Instances 

Thonny Modules Selection List

Thonny can support a variety of different modules. But if you want to connect to multiple modules at the same time, you need to run several instances of Thonny simultaneously. By default, only one instance is allowed. In the Tools -> Options -> General menu, untick the Allow only single Thonny instance checkbox.

I noticed one quirk on MacOS, however. For some reason, unchecking that option doesn’t work when launching the app from the GUI. There is a workaround — you can get multiple instances running if you start them from the command line.

One more annoyance — by default, Thonny will use the previous interpreter / connection when starting up. This is reasonable behavior, but causes a hiccup when talking to multiple boards simultaneously. Just ignore the plethora of error messages when Thonny instance #2 tries to connect to an already connected module, and use the menus to connect to the second device. There apparently isn’t any command line argument for a specific connection, but I have an inquiry pending on the GitHub project page.

Tip of the Iceberg

I have only focused on the WebREPL connectivity aspect of Thonny here, a functionality which seems to be uncommon in other MicroPython programming workflows. But this only scratches the surface of Thonny. Under the hood, it has a lot to offer that is hidden when you first open it.

And while I have been using its MicroPython mode of operation, Thonny was designed to aid students who are learning to write and debug “normal” Python programs running on desktop computers. If you frequently work in Python, I would encourage you to have a look at these aspects of the program — an object inspector, debugger, single-stepping, and a whole slew of other useful tools.

Thonny is also a multi-platform tool. While preparing this article, I tested it on MacOS, Windows 10, Debian, Ubuntu, and Raspberry Pi computers with no problems. The project is open-sourced under the MIT License.

At the very least, Thonny is a great solution for remote MicroPython programming of WiFi embedded modules. Check it out and give it a test run, especially if you’re lazy like me.

Best Python Training Institute in Noida

APTRON Solutions is the best IT Training Institute for Python course in Noida. APTRON Solutions also provides Internship and Inplant training in Python. Enhance your skills by mastering python course at APTRON Solutions. Develop portfolio projects with us and showcase your new skills to get your dream job.