Standard Library & Built-in Functions

Learn which libraries and built-in functions can be used with Transcrypt.

Introduction

The focus of Transcrypt is on applications that run in web browsers and not desktop applications. It is intended to be used more with JavaScript libraries rather than Python libraries. As such, it does not have a full set of standard Python modules available to it. However, in addition to supporting most of Python’s built-ins, a few standard Python modules have been added to the Transcrypt distribution that can be imported into our Python module.

Standard library

This list is bound to grow over time as the Transcrypt project matures, but for now, we only have these modules from the standard library available to us:

  • math
  • cmath
  • time (does not have sleep function for web browser use)
  • datetime
  • itertools
  • logging
  • warnings
  • random (partially)
  • re (partially)
  • turtle

In addition to the above, there is also a separate project called Numscrypt under development that is porting the Python NumPy library as well.

Python dataclasses is one language construct that works really well with React for storing component state. Though while being syntactically supported none of the methods like replace() or asdict() for dataclasses have been implemented in Transcrypt yet. So if we want to use them, we’ll have to provide that additional functionality ourselves for now.

Built-in functions

Despite the limitations of not having full Python standard library functionality, we’ll find that most of the other Python-related language constructs have been implemented. Working with standard Python objects like lists, dictionaries, strings, and more will feel just like Python should. There are only a few Python built-ins that have yet to be implemented, namely exec and eval, which are likely not needed in a web browser environment anyway. Then there are a few others like bin, oct, and hex for converting numbers, but those can easily be replaced with the toString(radix) method in JavaScript:

Get hands-on with 1400+ tech skills courses.