Skip to main content

No project description provided

Project description

Is Python an interpreted or compiled language? Trick question. It’s actually both. With tools like Cython, we can take the compilation step further and remove the interpreter loop almost entirely. Cython produces binaries much like C++, Go, and Rust do. Now with GitHub Actions the cross-platform build and release process can be automated for free for Open Source projects. This is an enormous opportunity to make the Python ecosystem 20-50% faster with a single pull request. This lightning talk walks through a GitHub workflow that publishes Cython-optimized wheels to PyPI. Discover how Cython can turbo-charge your Python code and GitHub Actions can simplify your cross-platform release process for free.

SF Python Holiday Party 2019

Is Python interpreted or compiled?

.
.
.
?
.
.
.
?
.
.
.
?

c2f.py

"Celsius to Fahrenheit Library"

def convert(celsius: float) -> float:
    "Convert Celsius to Fahrenheit"
    fahrenheit = celsius * 1.8 + 32
    return fahrenheit

c2f.cpython-38.pyc

>>> import c2f
>>> dis.dis(c2f.convert)
  6           0 LOAD_FAST                0 (celsius)
              2 LOAD_CONST               1 (1.8)
              4 BINARY_MULTIPLY
              6 LOAD_CONST               2 (32)
              8 BINARY_ADD
             10 STORE_FAST               1 (fahrenheit)
  7          12 LOAD_FAST                1 (fahrenheit)
             14 RETURN_VALUE

setup.py

from setuptools import setup
from Cython.Build import cythonize

setup(
    name='c2f',
    version='0.0.0',
    py_modules=['c2f'],
    ext_modules=cythonize('c2f.py'),
)

c2f.c

$ cython c2f.py
static PyObject * __pyx_convert(double __pyx_v_celsius)
{
  double __pyx_v_fahrenheit;
  PyObject *__pyx_r = NULL;
  __pyx_v_fahrenheit = ((__pyx_v_celsius * 1.8) + 32.0);
  __pyx_r = PyFloat_FromDouble(__pyx_v_fahrenheit);
  return __pyx_r;
}

c2f.so

$ python setup.py bdist_wheel
___pyx_convert:
push   rbp
mov    rbp, rsp
sub    rsp, 16
movsd  xmm0, qword ptr [rbp - 8]
mulsd  xmm0, qword ptr [rip + 1379]
addsd  xmm0, qword ptr [rip + 1379]
call   502 <PyFloat_FromDouble ...>
add    rsp, 16
pop    rbp
ret

.github/workflows/release.yml

name: release
on:
  push:
    tags:
      - v*
jobs:
  build-linux-cp38:
    runs-on: ubuntu-latest
    container: quay.io/pypa/manylinux2014_x86_64
    steps:
    ...

Matrix Build

build-macos:
  runs-on: macos-latest
  strategy:
    max-parallel: 4
    matrix:
      python-version: [3.5, 3.6, 3.7, 3.8]
  steps:
  ...

Mac Build Steps

- name: Set up Python ${{ matrix.python-version }} x64
  uses: actions/setup-python@v1
  with:
    python-version: ${{ matrix.python-version }}
    architecture: x64

- name: Install package dependencies
  run: pip install cython wheel

- name: Build binary wheel
  run: python setup.py bdist_wheel

Linux auditwheel Tool

- name: Build binary wheel
  run: /opt/python/cp38-cp38/bin/python setup.py bdist_wheel

- name: Apply auditwheel for manylinux wheel
  run: auditwheel repair -w dist dist/*

- name: Remove linux wheel
  run: rm dist/*-linux_x86_64.whl

Windows Build Steps

- name: Download Build Tools for Visual Studio 2019
  run: Invoke-WebRequest -Uri https://aka.ms/vs/16/rel...

- name: Run vs_buildtools.exe install
  run: ./vs_buildtools.exe --quiet --wait --norestart ...

Store Build Artifacts

- name: Archive dist artifacts
  uses: actions/upload-artifact@v1
  with:
    name: dist-macos-${{ matrix.python-version }}
    path: dist

Source Distribution

upload:
  needs: [build-linux-cp35, ...]
  runs-on: ubuntu-latest
  steps:
  ...
  - name: Install dependencies
    run: pip install -r requirements.txt

  - name: Create source dist
    run: python setup.py sdist

Stage Binary Wheels

- name: Stage linux 3.8
  uses: actions/download-artifact@v1
  with:
    name: dist-linux-3.8
- run: mv -v dist-linux-3.8/* dist/

- name: Stage macos 3.8
  uses: actions/download-artifact@v1
  with:
    name: dist-macos-3.8
- run: mv -v dist-macos-3.8/* dist/
...

Upload with Twine

- name: Upload with twine
  env:
    TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
    TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
  run: |
    ls -l dist/*
    pip install twine
    twine upload dist/*

Cythonize all the Things!

PLEASE STEAL THE CODE!

Cythonize all the Things!

Cythonize all the Things!

Cythonize all the Things!

Cythonize all the Things!

Cythonize all the Things!

Cythonize all the Things!

Appendix

Dumping Assembly

$ gcc -g -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 -L/Library/Frameworks/Python.framework/Versions/3.8/lib -o c2f.so c2f.c -lpython3.8
$ objdump -S -df=___pyx_pw_3c2f_1convert c2f.so

Git Tagging

$ git tag -a v0.0.2 -m v0.0.2
$ git push
$ git push --tags

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

c2f-1.0.4.tar.gz (28.5 kB view details)

Uploaded Source

Built Distributions

c2f-1.0.4-cp38-cp38-win_amd64.whl (16.7 kB view details)

Uploaded CPython 3.8 Windows x86-64

c2f-1.0.4-cp38-cp38-manylinux2014_x86_64.whl (49.3 kB view details)

Uploaded CPython 3.8

c2f-1.0.4-cp38-cp38-manylinux1_x86_64.whl (49.3 kB view details)

Uploaded CPython 3.8

c2f-1.0.4-cp38-cp38-macosx_10_13_x86_64.whl (13.8 kB view details)

Uploaded CPython 3.8 macOS 10.13+ x86-64

c2f-1.0.4-cp37-cp37m-win_amd64.whl (16.6 kB view details)

Uploaded CPython 3.7m Windows x86-64

c2f-1.0.4-cp37-cp37m-manylinux2014_x86_64.whl (47.1 kB view details)

Uploaded CPython 3.7m

c2f-1.0.4-cp37-cp37m-manylinux1_x86_64.whl (47.1 kB view details)

Uploaded CPython 3.7m

c2f-1.0.4-cp37-cp37m-macosx_10_13_x86_64.whl (13.7 kB view details)

Uploaded CPython 3.7m macOS 10.13+ x86-64

c2f-1.0.4-cp36-cp36m-win_amd64.whl (21.0 kB view details)

Uploaded CPython 3.6m Windows x86-64

c2f-1.0.4-cp36-cp36m-manylinux2014_x86_64.whl (46.1 kB view details)

Uploaded CPython 3.6m

c2f-1.0.4-cp36-cp36m-manylinux1_x86_64.whl (46.1 kB view details)

Uploaded CPython 3.6m

c2f-1.0.4-cp36-cp36m-macosx_10_13_x86_64.whl (13.6 kB view details)

Uploaded CPython 3.6m macOS 10.13+ x86-64

c2f-1.0.4-cp35-cp35m-manylinux2014_x86_64.whl (45.4 kB view details)

Uploaded CPython 3.5m

c2f-1.0.4-cp35-cp35m-manylinux1_x86_64.whl (45.4 kB view details)

Uploaded CPython 3.5m

c2f-1.0.4-cp35-cp35m-macosx_10_13_x86_64.whl (13.5 kB view details)

Uploaded CPython 3.5m macOS 10.13+ x86-64

File details

Details for the file c2f-1.0.4.tar.gz.

File metadata

  • Download URL: c2f-1.0.4.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4.tar.gz
Algorithm Hash digest
SHA256 95884e59399d7756afa69b8bacb848c3ff9c9e0a2b63382d78a4126c4aa4f419
MD5 841ae2688ef7810439530644f6b17fb7
BLAKE2b-256 f2580056cfa238c3a35df75df173fca4ea59be8ecb8578ba295a87bd1459a2d2

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 139572af9be412eb565d58dc2fb2f1475b3075d77a7cf21bbe5335648e2b8aec
MD5 b7e6d06b37e68bc47cc864f961c7023c
BLAKE2b-256 4bd8d5b0c45b32c51f5b5ae5bb936d6e4b0be605caa9149a44624fcced880970

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 49.3 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 64487081b694c44de7c6aecbcc467d3e07156e443487285bfddbe7e163e66c13
MD5 729cecf76154c65eb96620cedea71aa7
BLAKE2b-256 58beb70c6eca421dd71b2dee523ab5264a6245bac3cdc99664de0202da6a3a6d

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 49.3 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b0a108a885231003b6f2965bc969a6623a0eb65d141f596fc1d05f419b1065d0
MD5 a2cddb752695cb73becc3745ab2dac30
BLAKE2b-256 dcf34bc153af0a4f4e5a66c584e4ee2491b060098c8ec92945e50638728ece0b

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp38-cp38-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp38-cp38-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: CPython 3.8, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 b8f09105b1c396567055a22ab80d76567d66314d470a533623c99833efe46db2
MD5 83ef1c0f54884735061657e223d14306
BLAKE2b-256 0c139fb5a50162b7bd8d93c86cd22f1510032be8b2f92eefb536722eedc54e79

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 5800ca3663fb085b6cd79ae483ad4543c86be840455a171cf90e3c69aefe9d62
MD5 8d34484f9b247464693b6d58fcd222c1
BLAKE2b-256 2176371f404f31633e7804d7edb9e304b3451c2dfdbe86b67d3d25b6674feb47

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 47.1 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b5ae7afb430a1cbe0e146fea82c74c24ed0eb74e1e89c9b4fe67f1295be02abc
MD5 b06c4cd9bf8fe86b660251a68221ba89
BLAKE2b-256 0bcbd7d73e7ec3a86186f8d37d903eb72291b3ae3983c9189577332b50b03bba

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 47.1 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 eb907ba7311a801fb4bfb6471dae669e6f9126ec3004b838d45bff8cb1eb5de5
MD5 5ba796a150f4064d78704c6491eddef0
BLAKE2b-256 0deeffbd06531e7c15509a3941339ee42faa6cb100e8b4d3ff48b9a08f0e731f

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp37-cp37m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp37-cp37m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: CPython 3.7m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 baf4bae9e2ad637cbccf8327276cadff628122b2d28c127970e1a074312ff71a
MD5 1a7ae3185079c22425b21bbc0ea15dc8
BLAKE2b-256 64e7b9ea88a35eda1be19e9432dd659b9501d36a919a84fc126462d6aeaefb2a

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 327054b491a90e8b62189179bab9b5cbd7fd19d6fc66312c4fc05f3a7ec9af22
MD5 17164afc790af4ba8e0ac52b0a514f1e
BLAKE2b-256 1c9ce423de764004d61cc0856fff9eab89c3dcc7d7c8bb22ae985e2072cc8745

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 46.1 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7c6a2685227a19c5bddc564a313d94822ca7a3020a62c5cb1d8bc1679f2d3a6c
MD5 d912b72cd29b49ebd56b7252bcc26466
BLAKE2b-256 f5a55cb5374b81c521243cc29376b9bbe512a74a97ca8e804d1607fef32829c3

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 46.1 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 66a586981d1a5e40bff84bf1e703187f2f1a91d171c45f747ac7435f4080da1d
MD5 775c0fbfa12b9f1e18f766a7bb29d313
BLAKE2b-256 a24112a1b59851a9afd04dea5946c8c4afe4a485202c2209efe669b320229aaf

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp36-cp36m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp36-cp36m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: CPython 3.6m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 ae077f74387b8b9df50ba1843fc62b236dfadaceb190387182177b60ef0baa39
MD5 baf84a3496a4921bcc41f859561f8723
BLAKE2b-256 4a437224c718d76ec17d00cab72333b8239944da3711f9cab02e7bf7eba4e8b3

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp35-cp35m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp35-cp35m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 45.4 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9416556c54f4e76fdb8fd2626c7d83d0f2bb22228153c11dc4b807736ad1369e
MD5 d18f741d2e2c01410e51bcbad0366864
BLAKE2b-256 4bcee35d6c1bd931d47d874288d9946f5e2022a03120f3a9a3f218c8ced47128

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 45.4 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 af8932b01af514f065a863bd9f68794c992afaeec91d37af636388548c5920df
MD5 947635640bf08c729b23681117aea327
BLAKE2b-256 bef0c254be101738affcd9ad062156b10d43475c4d4687fc29d950bab70f9526

See more details on using hashes here.

File details

Details for the file c2f-1.0.4-cp35-cp35m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: c2f-1.0.4-cp35-cp35m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: CPython 3.5m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.8.0

File hashes

Hashes for c2f-1.0.4-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 868ad2dd6cf124d6c98244feef27ea9026ff9210fa108a53a8aef8f5b5e02c69
MD5 65e0dbe15a198a127893f2d810835119
BLAKE2b-256 8a0cd5ca4a07352b3fc6ce845733885b1744d37215abbee748213a734837844e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page