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 will walk 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

Grant Jenks
Dec. 4, 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!

Grant Jenks
Dec. 4, 2019

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.3.tar.gz (28.3 kB view details)

Uploaded Source

Built Distributions

c2f-1.0.3-cp38-cp38-win_amd64.whl (16.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

c2f-1.0.3-cp38-cp38-manylinux2014_x86_64.whl (49.2 kB view details)

Uploaded CPython 3.8

c2f-1.0.3-cp38-cp38-manylinux1_x86_64.whl (49.2 kB view details)

Uploaded CPython 3.8

c2f-1.0.3-cp38-cp38-macosx_10_13_x86_64.whl (13.7 kB view details)

Uploaded CPython 3.8 macOS 10.13+ x86-64

c2f-1.0.3-cp37-cp37m-win_amd64.whl (16.5 kB view details)

Uploaded CPython 3.7m Windows x86-64

c2f-1.0.3-cp37-cp37m-manylinux2014_x86_64.whl (47.0 kB view details)

Uploaded CPython 3.7m

c2f-1.0.3-cp37-cp37m-manylinux1_x86_64.whl (47.0 kB view details)

Uploaded CPython 3.7m

c2f-1.0.3-cp37-cp37m-macosx_10_13_x86_64.whl (13.6 kB view details)

Uploaded CPython 3.7m macOS 10.13+ x86-64

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

Uploaded CPython 3.6m Windows x86-64

c2f-1.0.3-cp36-cp36m-manylinux2014_x86_64.whl (46.0 kB view details)

Uploaded CPython 3.6m

c2f-1.0.3-cp36-cp36m-manylinux1_x86_64.whl (46.0 kB view details)

Uploaded CPython 3.6m

c2f-1.0.3-cp36-cp36m-macosx_10_13_x86_64.whl (13.5 kB view details)

Uploaded CPython 3.6m macOS 10.13+ x86-64

c2f-1.0.3-cp35-cp35m-manylinux2014_x86_64.whl (45.3 kB view details)

Uploaded CPython 3.5m

c2f-1.0.3-cp35-cp35m-manylinux1_x86_64.whl (45.3 kB view details)

Uploaded CPython 3.5m

c2f-1.0.3-cp35-cp35m-macosx_10_13_x86_64.whl (13.4 kB view details)

Uploaded CPython 3.5m macOS 10.13+ x86-64

File details

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

File metadata

  • Download URL: c2f-1.0.3.tar.gz
  • Upload date:
  • Size: 28.3 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.3.tar.gz
Algorithm Hash digest
SHA256 ce812272cc3041afb8517b3d538c720847303563d9105f59173a1d2f1c271fd0
MD5 3ca8f11d83f4f5b0c083e088a2698b3b
BLAKE2b-256 0625d181974b8f3e9838e0f079f108ad8de143c4061655140dd3e64624f22b8a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 16.6 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.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 0b370b96b2094a4fb572ed3cff96c2785814ec8141e05bf15f8145dfcc75280e
MD5 cdff4b3cc52714d1de4bf3fd72cecc4e
BLAKE2b-256 5038aa149e518e8e536e8fa30a736cfed6f0b1488e4e32818a8fafe5676dfcb3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 49.2 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.3-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 80d0ffd807acae19ad7b6c48244115ed14bdd6d3f274d9aecb9663e3ddf86bbf
MD5 342bcbc066d7bc5e2b63991fadd08354
BLAKE2b-256 aed1b440c045890d65d971ff547823c7162a10edf059505c10c20f7e84eb1751

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 49.2 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.3-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5096240d79ed4e9bbf7c60395b5582d47781f09929245a2086e2e77e1d8b0aec
MD5 d73e4ced675a4a4fc652b779bfbe3b2b
BLAKE2b-256 2a1d8a352325b330bac6e5f6561ac13473eeca37a3a22b7b1ed706aaa6512701

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-cp38-cp38-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 13.7 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.3-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 7b0f6d1800e669d140ab01159dceb75a306190dfeccfb12799bd546abf2a9fc0
MD5 cfe66df5227e1a825d8e1d918aee87fd
BLAKE2b-256 db941972af50e878618f57cc14c2a8a21b0d72ac49ec176c97132a19f3dc9140

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 16.5 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.3-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ed4a3864ea45132e6d8ba5a019f25ddd2a5a2e22ebb7888f9250bbf469fed827
MD5 872c001674a9a739711885c7f3115e56
BLAKE2b-256 ec8926e31b84cd529015e9557bda0fa4b9ab27a22811caa6b7225541f8f4d27d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 47.0 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.3-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f29a984b0ee76126dbd60b4a4774fb7c0203d180ef18ab575284c267df9e2dd5
MD5 ab5d8b4707c466419aaa0da33011e7dc
BLAKE2b-256 d107e793fbc1042185a82d9052916798dc659fd600ec8cca4e378a2b38fa5a50

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 47.0 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.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 385fb3e3b94994fc048969caa385965eb280e1cdc4e1b96cd1edf5952de55e8d
MD5 21672c01f3f0a462c23d024033da6844
BLAKE2b-256 029b04c5d342503506e1d21b7a2fae764c6cd0e7f7c7d9129fe93237973c8892

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-cp37-cp37m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 13.6 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.3-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 b2c48a57721053eb5fd324709884746a60e8eabe42b94899ee4715642d379c95
MD5 544947dd836962b0b9e497e10326d700
BLAKE2b-256 4716255cc458de685b9ee0302e28d53e2af9d906cf565506aeceb4ffb09131c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-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.3-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 6051384a6705652310f1d06ba950dfbc3caa1d178dd4d84590532cb8306db2f7
MD5 12cd275e2c5db7a50ad51264193c72fd
BLAKE2b-256 bcbb5ea189f9d2c1c6cfa36a0ab9203b8419c7f1f014115973f4a5c1bf52d027

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 46.0 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.3-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 daadeedba2a5ac35152d1e5b68381ce977cdbde3604ea0c2f38387e2bcfe6484
MD5 3a8d671b64f2a0a32eb4e0cdece5da2b
BLAKE2b-256 9e59c1fdebb9335d741edacbd237cb05df98f2cae772f7147b89bbf4032ed54d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 46.0 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.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a6dcc9aa7b935beba3b5091fcb1e1a7d29ae3cc2e4839cf8c70b56ac0334ef47
MD5 f9c84769b8f3f25312f2f37a07899486
BLAKE2b-256 40f72d4d46d508cc4a52661338c444b694279758c2dd6be2f197b4d47dfdd2ee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-cp36-cp36m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 13.5 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.3-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 bbc44b01a1c91ed8deb9f89f35eb6631fa3bab0dee99cabb1f0772687c772ec7
MD5 baafc4e5dfcd0ecb84b7b6593d20d3d2
BLAKE2b-256 f2e3889441c6f743d21fe2b8be8239bcd8f711d96324f02e7e3490d9567241c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-cp35-cp35m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 45.3 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.3-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 93cc7b8fa4dd73410983d67892038877eeb4e1345990013461e4c16049ec0040
MD5 4fae56f323631a952b5f1a8439cc093d
BLAKE2b-256 e8f4bf05b60e2754cb81d8e6d2577f864f2ec321fa2bdeb37f8b13fd1543e4b8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 45.3 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.3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c9ad72d6b7ce4451c455f65b70ac9f4348c6e6af9139078001a2e6d8aef32e4a
MD5 83daf96a62de68965e2d30fc28ad7cec
BLAKE2b-256 c3aa376a7d94f0879fc16fa295a7daedacb7f403917e668d06bd57efed8ce0b7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: c2f-1.0.3-cp35-cp35m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 13.4 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.3-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 670c2d057f75f3549b70fb8f634a55012a10219d9c69cd2ce737f3c8e3be6e0a
MD5 960ea7c1257c5ef110e2058dd8f91ba7
BLAKE2b-256 a492c238d2d15350d2cd1b7ebb6c6d692154fc76cc011a382adbbbf783885c63

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