Serverless is a deployment architecture where servers are not explicitly provisioned by the deployer. Code is instead executed based on developer-defined events that are triggered, for example when an HTTP POST request is sent to an API a new line written to a file.

How can code be executed "without" servers?

Servers still exist to execute the code but they are abstracted away from the developer and handled by a compute platform such as Amazon Web Services Lambda or Google Cloud Functions.

Serverless compute spectrum.

Think about deploying code as a spectrum, where on one side you build your own server from components, hook it up to the internet with a static IP address, connect the IP address to DNS and start serving requests. The hardware, operating system, web server, WSGI server, etc are all completely controlled by you. On the opposite side of the spectrum are serverless compute platforms that take Python code and execute it without you ever touching hardware or even knowing what operating system it runs on.

In between those extremes are levels that remove the need to worry about hardware (virtual private servers), up through removing concerns about web servers (platforms-as-a-service). Where you fall on the spectrum for your deployment will depend on your own situation. Serverless is simply the newest and most extreme of these deployment models so it is up to you as to how much complexity you want to take on with the deployment versus your control over each aspect of the hardware and software.

Serverless implementations

Each major cloud vendor has a serverless compute implementation. These implementations are under significant active developer and not all of them have Python support.

  • AWS Lambda is the current leader among serverless compute implementations. It has support for both Python 2.7 and Python 3.6.

  • Azure Functions has second-class citizen support for Python. It's supposed to be possible but kind of hacky at the moment. Polyglot support should be quickly coming to Azure to better compete with AWS Lambda.

  • IBM Bluemix OpenWhisk is based on the Apache OpenWhisk open source project.

  • Google Cloud Functions currently only supports JavaScript code execution.

  • also only supports JavaScript but there is a cool prototype project named webtask-pytask to run Python code in the browser via webtask. This demo is definitely not for production code use but awesome to see what the programming community can put together using existing code and services.

Serverless frameworks

Serverless libraries and frameworks aim to provide reusable code that handles common or tedious tasks, similar to how web frameworks deal with common web development tasks. Some of these frameworks are built for a single service like AWS Lambda, while others attempt to make cross-serverless operations more palatable.

Frameworks for building Python-based applications on serverless services include:

  • Serverless (source code), which is a useful but generically-named library that focuses on deployment and operations for serverless applications.

  • Zappa (source code) provides code and tools to make it much easier to build on AWS Lambda and AWS API Gateway than rolling your own on the bare services.

  • Chalice (source code) is built by the AWS team specifically for Python applications.

  • Apex (source code)

General serverless resources

Serverless concepts and implementations are still in their early iterations so there are many ideas and good practices yet to be discovered. These resources are the first attempts at figuring out how to structure and operate serverless applications.

Serverless vendor lock-in?

There is some concern by organizations and developers about vendor lock-in on serverless platforms. It is unclear if portability is worse for serverless than other infrastructure-as-a-service pieces, but still worth thinking about ahead of time. These resources provide additional perspectives on lock-in and using multiple cloud providers.

What else do you want to learn about serverless and deployments?

I've built a Python web app, now how do I deploy it?

What is Docker and how does it fit with Python deployments?

Tell me about standard relational databases.

Sign up for two emails per month with Python tutorials and Full Stack Python updates.

Sponsored By

Rollbar logo

Fix errors in your Python applications before your users ever see them by monitoring your app with Rollbar.

Full Stack Python

Full Stack Python is an open book that explains concepts in plain language and provides helpful resources for those topics.
Updates via newsletter, Twitter & Facebook.
1. IntroductionLearning ProgrammingWhy Use Python?Python 2 or 3?Enterprise PythonPython CommunityCompanies using PythonBest Python ResourcesBest Python VideosBest Python Podcasts2. Development EnvironmentsText Editors & IDEsVimEmacsSublime TextPyCharmJupyter NotebookBash shellShellsZshPowerShellTerminal MultiplexerstmuxScreenPymuxEnvironment configurationApplication DependenciesSource ControlGitMercurialApache SubversionHosted Source ControlGitHubBitBucketGitLab3. Core LanguageGeneratorsComprehensions4. TestingUnit TestingIntegration TestingCode MetricsDebuggingLoggingMarkdown6. Security7. Web DevelopmentWeb FrameworksDjangoFlaskBottlePyramidFalconMorepathSanicOther Web FrameworksTemplate EnginesJinja2MakoDjango TemplatesWeb DesignCascading Style Sheets (CSS)HTMLResponsive DesignMinificationBootstrapJavaScriptTask QueuesCeleryRedis Queue (RQ)DramatiqStatic Site GeneratorsPelicanLektorMkDocsWebSocketsuvloop8. DeploymentServersStatic ContentPlatform-as-a-ServiceVirtual Private ServersOperating SystemsUbuntuWeb ServersApache HTTP ServerNginxCaddyWSGI ServersGreen Unicorn (Gunicorn)Continuous IntegrationJenkinsConfiguration ManagementAnsibleDockerServerlessAWS LambdaGoogle Cloud Functions9. DataRelational DatabasesPostgreSQLMySQLSQLiteObject-relational MappersSQLAlchemyPeeweeDjango ORMSQLObjectPony ORMNoSQL Data StoresRedisMongoDBApache CassandraNeo4jData analysispandasBokehd3.jsMatplotlib10. Web APIsMicroservicesBotsAPI CreationAPI IntegrationTwilio11. DevOpsMonitoringCachingRollbarWeb Analytics12. Change LogWhat Full Stack MeansAbout the AuthorFuture DirectionsPage Statuses ...or view all topics.

Matt Makai 2012-2018