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 multi purpose language is also a big player in the world of web development and 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 are bored of writing self.attribute = attribute
in your __init__
methods all the time, you might like Data classes, documented in PEP 557. Class definition and creation of the object, storing a bunch of data can be really easy now:
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 is 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 much more features and fixes, 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.
PIP 18.0
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. Pip development team have 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 contains also a 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 so on Platform.sh! The only thing you have to do is to put following line into your .platform.app.yaml
file:
type: "python:3.7"
Commit the changes, push your code and enjoy the flight!