README.md 3.21 KB
Newer Older
Kenneth Reitz's avatar
Kenneth Reitz committed
1
![python](https://cloud.githubusercontent.com/assets/51578/13712821/b68a42ce-e793-11e5-96b0-d8eb978137ba.png)
Kenneth Reitz's avatar
yes  
Kenneth Reitz committed
2

Kenneth Reitz's avatar
no  
Kenneth Reitz committed
3
# Heroku Buildpack: Python
4

Kenneth Reitz's avatar
Kenneth Reitz committed
5
[![Build Status](https://travis-ci.org/heroku/heroku-buildpack-python.svg?branch=master)](https://travis-ci.org/heroku/heroku-buildpack-python)
Kenneth Reitz's avatar
Kenneth Reitz committed
6

Casey Faist's avatar
Casey Faist committed
7
This is the official [Heroku buildpack](https://devcenter.heroku.com/articles/buildpacks) for Python apps.
Nahid Samsami's avatar
Nahid Samsami committed
8

Casey Faist's avatar
Casey Faist committed
9
Recommended web frameworks include **Django** and **Flask**, among others. The recommended webserver is **Gunicorn**. There are no restrictions around what software can be used (as long as it's pip-installable). Web processes must bind to `$PORT`, and only the HTTP protocol is permitted for incoming connections.
Kenneth Reitz's avatar
Kenneth Reitz committed
10

Casey Faist's avatar
Casey Faist committed
11
Python packages with C dependencies that are not [available on the stack image](https://devcenter.heroku.com/articles/stack-packages) are generally not supported, unless `manylinux` wheels are provided by the package maintainers (common). For recommended solutions, check out [this article](https://devcenter.heroku.com/articles/python-c-deps) for more information.
Kenneth Reitz's avatar
Kenneth Reitz committed
12

Kenneth Reitz's avatar
Kenneth Reitz committed
13 14
See it in Action
----------------
Casey Faist's avatar
Casey Faist committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28
```
$ ls
my-application		requirements.txt	runtime.txt

$ git push heroku master
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 276 bytes | 276.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
codeinteger6's avatar
codeinteger6 committed
29
remote: -----> Installing python-3.7.4
Casey Faist's avatar
Casey Faist committed
30 31 32 33 34 35 36 37 38 39 40 41
remote: -----> Installing pip
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote:        Collecting flask (from -r /tmp/build_c2c067ef79ff14c9bf1aed6796f9ed1f/requirements.txt (line 1))
remote:          Downloading ...
remote:        Installing collected packages: Werkzeug, click, MarkupSafe, Jinja2, itsdangerous, flask
remote:        Successfully installed Jinja2-2.10 MarkupSafe-1.1.0 Werkzeug-0.14.1 click-7.0 flask-1.0.2 itsdangerous-1.1.0
remote:
remote: -----> Discovering process types
remote:        Procfile declares types -> (none)
remote:
```
42

Casey Faist's avatar
Casey Faist committed
43
A `requirements.txt` must be present at the root of your application's repository to deploy.
Noah Zoschke's avatar
Noah Zoschke committed
44

Casey Faist's avatar
Casey Faist committed
45
To specify your python version, you also need a `runtime.txt` file - unless you are using the default Python runtime version.
Noah Zoschke's avatar
Noah Zoschke committed
46

codeinteger6's avatar
codeinteger6 committed
47
Current default Python Runtime: Python 3.6.9
Noah Zoschke's avatar
Noah Zoschke committed
48

Casey Faist's avatar
Casey Faist committed
49
Alternatively, you can provide a `setup.py` file, or a `Pipfile`. Using `Pipenv` will generate `runtime.txt` based on `python-version` at build time.
Noah Zoschke's avatar
Noah Zoschke committed
50

Casey Faist's avatar
Casey Faist committed
51 52
Specify a Buildpack Version
---------------------------
Kenneth Reitz's avatar
Kenneth Reitz committed
53

Casey Faist's avatar
Casey Faist committed
54
You can specify the latest production release of this buildpack for upcoming builds of an existing application:
Kenneth Reitz's avatar
Kenneth Reitz committed
55

Kenneth Reitz's avatar
Kenneth Reitz committed
56
    $ heroku buildpacks:set heroku/python
Kenneth Reitz's avatar
Kenneth Reitz committed
57

Kenneth Reitz's avatar
Kenneth Reitz committed
58

Kenneth Reitz's avatar
Kenneth Reitz committed
59 60
Specify a Python Runtime
------------------------
Kenneth Reitz's avatar
Kenneth Reitz committed
61

Casey Faist's avatar
Casey Faist committed
62
Supported runtime options include:
Kenneth Reitz's avatar
Kenneth Reitz committed
63

codeinteger6's avatar
codeinteger6 committed
64 65
- `python-3.7.4`
- `python-3.6.9`
Casey Faist's avatar
Casey Faist committed
66
- `python-2.7.17`
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

## Tests

The buildpack tests use [Docker](https://www.docker.com/) to simulate
Heroku's [stack images.](https://devcenter.heroku.com/articles/stack)

To run the test suite:

```
make test
```

Or to test in a particular stack:

```
make test-heroku-18
make test-heroku-16
```

The tests are run via the vendored
[shunit2](https://github.com/kward/shunit2)
Casey Faist's avatar
Casey Faist committed
88
test framework.