mypyc_ipython
IPython magic command interface for interactive work with mypyc, a compiler from type-annotated Python to C extensions.
Installation
Supported Python versions are 3.6 or later.
$ pip install mypyc-ipython
Usage
You can use this library like %%cython magic command.
- Execute
%load_ext mypyc_ipythonto enable the magic. - Write the code in
%%mypyccode cell.
In [1]: %load_ext mypyc_ipython
In [2]: %%mypyc
...: def my_fibonacci(n: int) -> int:
...: if n <= 2:
...: return 1
...: else:
...: return my_fibonacci(n-1) + my_fibonacci(n-2)
...:
In [3]: my_fibonacci(10)
Out[3]: 55
In [4]: def py_fibonacci(n: int) -> int:
...: if n <= 2:
...: return 1
...: else:
...: return py_fibonacci(n-1) + py_fibonacci(n-2)
...:
In [5]: py_fibonacci(10)
Out[5]: 55
In [6]: %load_ext cython
In [7]: %%cython
...: cpdef int cy_fibonacci(int n):
...: if n <= 2:
...: return 1
...: else:
...: return cy_fibonacci(n-1) + cy_fibonacci(n-2)
...:
In [8]: cy_fibonacci(10)
Out[8]: 55
In [9]: %timeit py_fibonacci(10)
10.3 µs ± 30.2 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
In [10]: %timeit my_fibonacci(10)
848 ns ± 5.82 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
In [11]: %timeit cy_fibonacci(10)
142 ns ± 1.18 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
In [12]:
The contents of the cell are written to a .py file in the directory IPYTHONDIR/mypyc
using a filename with the hash of the code. This file is then mypycified and compiled.
The resulting module is imported and all of its symbols are injected into the user's namespace.
If you want to disable the cache, you can use --force option like this:
In [2]: %%mypyc --force
...: def my_fibonacci(n: int) -> int:
...: if n <= 2:
...: return 1
...: else:
...: return my_fibonacci(n-1) + my_fibonacci(n-2)
Author
Masashi Shibata (@c-bata)
License
MIT License
Metadata
Release files for mypyc-ipython 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mypyc_ipython-0.0.2.tar.gz | 4.7 kB | Without provenance | Details for mypyc_ipython-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mypyc_ipython-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for mypyc_ipython-0.0.2-py3-none-any.whl |
Total release size: 10.3 kB
Release files / mypyc_ipython-0.0.2.tar.gz
| Download URL | mypyc_ipython-0.0.2.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e265704ac98c3c42df404d7066f8c122a6fcb4ef6d88410ed84d60979d1b6bea
|
|
BLAKE2b-256 checksum How to use checksums |
9806fccbcdee7ef78f7481754ed83356d8e8049b7e48dd12a2b5a34c5dde6425
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.6
|
Release files / mypyc_ipython-0.0.2-py3-none-any.whl
| Download URL | mypyc_ipython-0.0.2-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb8057908781a01cebf564b753be56cec17247d6f10a5ed0cba5d93636de6a00
|
|
BLAKE2b-256 checksum How to use checksums |
532e18dbcbb6223f752f929c9f69a02037eaf1e262cefbded02640f0dcd49800
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.6
|
Security for mypyc-ipython 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.