Deploy your Python 3.7 code to the Moon
Python is one of the most popular programming languages of the last decade (hey, most of Platform.sh is written in Python!). It doesn't matter if you do data science, develop a video game, or you just need to write a quick-and-dirty script. Python will always serve you well. This multipurpose language is also a big player in the world of web development; that's why the batteries included infrastructure for building and deploying your Python projects is available on Platform.sh, and we've just added Python 3.7 to the list of supported versions.
What's new in 3.7?
The latest major release of the language introduces many cool new features. In case you're bored of writing
self.attribute = attribute in your
__init__ methods all the time, you might like Data classes, documented in PEP 557. Now, class definition and creation of the object, storing a bunch of data can be really easy:
from dataclasses import dataclass @dataclass class C: i: int j: int = None database: InitVar[DatabaseType] = None def __post_init__(self, database): if self.j is None and database is not None: self.j = database.lookup('j') c = C(10, database=my_database)
Note the types are just documentation. They aren’t examined at runtime.
Another visible change is the new
breakpoint() built-in function, which makes debugging your code smoother. It can be put anywhere in the code instead of
import pdb; pdb.set_trace() line. The main benefit of
breakpoint() is that it's configurable via the
PYTHONBREAKPOINT environment variable. You can simply ignore all the
breakpoint() calls in your code by setting its value to zero:
$ PYTHONBREAKPOINT=0 python3.7 script.py
or switch to use a debugger of your choice instead of the default PDB:
$ PYTHONBREAKPOINT=pudb.set_trace python3.7 script.py
The asyncio standard library module has received many new features, too. For example, the new
asyncio.run() function removes the burden of creating the event loop explicitly. Creating a trivial coroutine is now as simple as this:
import asyncio async def hello_world(): print("Hello World!") asyncio.run(hello_world())
Python 3.7 brings also performance improvement, higher precision timing functions, typing enhancements, and many more features and fixes. You can take a look at the official documentation for the complete list. Be aware that Python 3.7 final was released upstream only a couple of months ago and older versions of some Python libraries and frameworks like Django < 2.0, gevent < 1.3.6 are not fully compatible with the latest Python version.
The brand new Pip 18.0 is coming to Platform.sh, alongside new the Python release! Version number might be a bit surprising. We all remember using Pip version 9 or 10 recently. The Pip development team has switched to a calendar-based versioning scheme. This is not the only thing that changed. Support for packages, specifying build system requirements in
pyproject.toml file, aka PEP 518 was introduced in version 10 and improved in the latest release. Last two releases also contain plenty of fixes. See the relase notes for more information.
Try it out!
Are you thrilled to try all these great features yourself? You can do it on Platform.sh! The only thing you have to do is put the following line into your
Commit the changes, push your code, and enjoy the flight!