Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1b6252

Browse files
miss-islingtonvstinnerencukouzooba
authored
[3.14]gh-133678: Document C API third party tools (GH-134526) (#134793)
gh-133678: Document C API third party tools (GH-134526)(cherry picked from commitc3c8806)Co-authored-by: Victor Stinner <vstinner@python.org>Co-authored-by: Petr Viktorin <encukou@gmail.com>Co-authored-by: Steve Dower <steve.dower@python.org>
1 parent00122c8 commita1b6252

File tree

4 files changed

+46
-35
lines changed

4 files changed

+46
-35
lines changed

‎Doc/c-api/intro.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,3 +844,41 @@ after every statement run by the interpreter.)
844844

845845
Please refer to:file:`Misc/SpecialBuilds.txt` in the Python source distribution
846846
for more detailed information.
847+
848+
849+
.. _c-api-tools:
850+
851+
Recommended third party tools
852+
=============================
853+
854+
The following third party tools offer both simpler and more sophisticated
855+
approaches to creating C, C++ and Rust extensions for Python:
856+
857+
* `Cython<https://cython.org/>`_
858+
* `cffi<https://cffi.readthedocs.io>`_
859+
* `HPy<https://hpyproject.org/>`_
860+
* `nanobind<https://github.com/wjakob/nanobind>`_ (C++)
861+
* `Numba<https://numba.pydata.org/>`_
862+
* `pybind11<https://pybind11.readthedocs.io/>`_ (C++)
863+
* `PyO3<https://pyo3.rs/>`_ (Rust)
864+
* `SWIG<https://www.swig.org>`_
865+
866+
Using tools such as these can help avoid writing code that is tightly bound to
867+
a particular version of CPython, avoid reference counting errors, and focus
868+
more on your own code than on using the CPython API. In general, new versions
869+
of Python can be supported by updating the tool, and your code will often use
870+
newer and more efficient APIs automatically. Some tools also support compiling
871+
for other implementations of Python from a single set of sources.
872+
873+
These projects are not supported by the same people who maintain Python, and
874+
issues need to be raised with the projects directly. Remember to check that the
875+
project is still maintained and supported, as the list above may become
876+
outdated.
877+
878+
..seealso::
879+
880+
`Python Packaging User Guide: Binary Extensions<https://packaging.python.org/guides/packaging-binary-extensions/>`_
881+
The Python Packaging User Guide not only covers several available
882+
tools that simplify the creation of binary extensions, but also
883+
discusses the various reasons why creating an extension module may be
884+
desirable in the first place.

‎Doc/extending/index.rst

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,9 @@ Recommended third party tools
2626
=============================
2727

2828
This guide only covers the basic tools for creating extensions provided
29-
as part of this version of CPython. Third party tools like
30-
`Cython<https://cython.org/>`_, `cffi<https://cffi.readthedocs.io>`_,
31-
`SWIG<https://www.swig.org>`_ and `Numba<https://numba.pydata.org/>`_
32-
offer both simpler and more sophisticated approaches to creating C and C++
33-
extensions for Python.
34-
35-
..seealso::
36-
37-
`Python Packaging User Guide: Binary Extensions<https://packaging.python.org/guides/packaging-binary-extensions/>`_
38-
The Python Packaging User Guide not only covers several available
39-
tools that simplify the creation of binary extensions, but also
40-
discusses the various reasons why creating an extension module may be
41-
desirable in the first place.
29+
as part of this version of CPython. Some:ref:`third party tools
30+
<c-api-tools>` offer both simpler and more sophisticated approaches to creating
31+
C and C++ extensions for Python.
4232

4333

4434
Creating extensions without third party tools

‎Doc/faq/extending.rst

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,9 @@ Writing C is hard; are there any alternatives?
3737
----------------------------------------------
3838

3939
There are a number of alternatives to writing your own C extensions, depending
40-
on what you're trying to do.
41-
42-
.. XXX make sure these all work
43-
44-
`Cython<https://cython.org>`_ and its relative `Pyrex
45-
<https://www.csse.canterbury.ac.nz/greg.ewing/python/Pyrex/>`_ are compilers
46-
that accept a slightly modified form of Python and generate the corresponding
47-
C code. Cython and Pyrex make it possible to write an extension without having
48-
to learn Python's C API.
49-
50-
If you need to interface to some C or C++ library for which no Python extension
51-
currently exists, you can try wrapping the library's data types and functions
52-
with a tool such as `SWIG<https://www.swig.org>`_. `SIP
53-
<https://github.com/Python-SIP/sip>`__, `CXX
54-
<https://cxx.sourceforge.net/>`_ `Boost
55-
<https://www.boost.org/libs/python/doc/index.html>`_, or `Weave
56-
<https://github.com/scipy/weave>`_ are also
57-
alternatives for wrapping C++ libraries.
40+
on what you're trying to do.:ref:`Recommended third party tools<c-api-tools>`
41+
offer both simpler and more sophisticated approaches to creating C and C++
42+
extensions for Python.
5843

5944

6045
How can I execute arbitrary Python statements from C?

‎Doc/howto/cporting.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ We recommend the following resources for porting extension modules to Python 3:
1414
module.
1515
* The `Porting guide`_ from the *py3c* project provides opinionated
1616
suggestions with supporting code.
17-
*The `Cython`_ and `CFFI`_ libraries offer abstractions over
18-
Python's C API.
17+
*:ref:`Recommended third party tools<c-api-tools>` offer abstractions over
18+
thePython's C API.
1919
Extensions generally need to be re-written to use one of them,
2020
but the library then handles differences between various Python
2121
versions and implementations.
2222

2323
.. _Migrating C extensions:http://python3porting.com/cextensions.html
2424
.. _Porting guide:https://py3c.readthedocs.io/en/latest/guide.html
25-
.. _Cython:https://cython.org/
26-
.. _CFFI:https://cffi.readthedocs.io/en/latest/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp