Skip to content

gh-133678: Add a banner to C API doc to recommend 3rd party tools #133679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Doc/c-api/abstract.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
Abstract Objects Layer
**********************

.. c-api-tools-banner::

The functions in this chapter interact with Python objects regardless of their
type, or with wide classes of object types (e.g. all numerical types, or all
sequence types). When used on object types for which they do not apply, they
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/allocation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Allocating Objects on the Heap
==============================

.. c-api-tools-banner::


.. c:function:: PyObject* _PyObject_New(PyTypeObject *type)

Expand Down
1 change: 1 addition & 0 deletions Doc/c-api/apiabiversion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
API and ABI Versioning
***********************

.. c-api-tools-banner::

Build-time version constants
----------------------------
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/arg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Parsing arguments and building values
=====================================

.. c-api-tools-banner::

These functions are useful when creating your own extension functions and
methods. Additional information and examples are available in
:ref:`extending-index`.
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/bool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Boolean Objects
---------------

.. c-api-tools-banner::

Booleans in Python are implemented as a subclass of integers. There are only
two booleans, :c:data:`Py_False` and :c:data:`Py_True`. As such, the normal
creation and deletion functions don't apply to booleans. The following macros
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/buffer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Buffer Protocol
.. sectionauthor:: Benjamin Peterson
.. sectionauthor:: Stefan Krah

.. c-api-tools-banner::


Certain objects available in Python wrap access to an underlying memory
array or *buffer*. Such objects include the built-in :class:`bytes` and
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/bytearray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Byte Array Objects

.. index:: pair: object; bytearray

.. c-api-tools-banner::


.. c:type:: PyByteArrayObject

Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/bytes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Bytes Objects
-------------

.. c-api-tools-banner::

These functions raise :exc:`TypeError` when expecting a bytes parameter and
called with a non-bytes parameter.

Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/call.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Call Protocol
=============

.. c-api-tools-banner::

CPython supports two different calling protocols:
*tp_call* and vectorcall.

Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/capsule.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Capsules

.. index:: pair: object; Capsule

.. c-api-tools-banner::

Refer to :ref:`using-capsules` for more information on using these objects.

.. versionadded:: 3.1
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/cell.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Cell Objects
------------

.. c-api-tools-banner::

"Cell" objects are used to implement variables referenced by multiple scopes.
For each such variable, a cell object is created to store the value; the local
variables of each stack frame that references the value contains a reference to
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Code Objects

.. sectionauthor:: Jeffrey Yasskin <jyasskin@gmail.com>

.. c-api-tools-banner::

Code objects are a low-level detail of the CPython implementation.
Each one represents a chunk of executable code that hasn't yet been
bound into a function.
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/codec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Codec registry and support functions
====================================

.. c-api-tools-banner::

.. c:function:: int PyCodec_Register(PyObject *search_function)

Register a new codec search function.
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/complex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Complex Number Objects

.. index:: pair: object; complex number

.. c-api-tools-banner::

Python's complex number objects are implemented as two distinct types when
viewed from the C API: one is the Python object exposed to Python programs, and
the other is a C structure which represents the actual complex number value.
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/concrete.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Concrete Objects Layer
**********************

.. c-api-tools-banner::

The functions in this chapter are specific to certain Python object types.
Passing them an object of the wrong type is not a good idea; if you receive an
object from a Python program and you are not sure that it has the right type,
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/contextvars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Context Variables Objects
-------------------------

.. c-api-tools-banner::

.. _contextvarsobjects_pointertype_change:
.. versionadded:: 3.7

Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/conversion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
String conversion and formatting
================================

.. c-api-tools-banner::

Functions for number conversion and formatted string output.


Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/coro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Coroutine Objects
-----------------

.. c-api-tools-banner::

.. versionadded:: 3.5

Coroutine objects are what functions declared with an ``async`` keyword
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
DateTime Objects
----------------

.. c-api-tools-banner::

Various date and time objects are supplied by the :mod:`datetime` module.
Before using any of these functions, the header file :file:`datetime.h` must be
included in your source (note that this is not included by :file:`Python.h`),
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/descriptor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Descriptor Objects
------------------

.. c-api-tools-banner::

"Descriptors" are objects that describe some attribute of an object. They are
found in the dictionary of type objects.

Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/dict.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Dictionary Objects

.. index:: pair: object; dictionary

.. c-api-tools-banner::


.. c:type:: PyDictObject

Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Exception Handling
******************

.. c-api-tools-banner::

The functions described in this chapter will let you handle and raise Python
exceptions. It is important to understand some of the basics of Python
exception handling. It works somewhat like the POSIX :c:data:`errno` variable:
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ File Objects

.. index:: pair: object; file

.. c-api-tools-banner::

These APIs are a minimal emulation of the Python 2 C API for built-in file
objects, which used to rely on the buffered I/O (:c:expr:`FILE*`) support
from the C standard library. In Python 3, files and streams use the new
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/float.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Floating-Point Objects

.. index:: pair: object; floating-point

.. c-api-tools-banner::


.. c:type:: PyFloatObject
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/frame.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Frame Objects
-------------

.. c-api-tools-banner::

.. c:type:: PyFrameObject

The C structure of the objects used to describe frame objects.
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/function.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Function Objects

.. index:: pair: object; function

.. c-api-tools-banner::

There are a few functions specific to Python functions.


Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/gcsupport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Supporting Cyclic Garbage Collection
====================================

.. c-api-tools-banner::

Python's support for detecting and collecting garbage which involves circular
references requires support from object types which are "containers" for other
objects which may also be containers. Types which do not store references to
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/gen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Generator Objects
-----------------

.. c-api-tools-banner::

Generator objects are what Python uses to implement generator iterators. They
are normally created by iterating over a function that yields values, rather
than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/hash.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
PyHash API
----------

.. c-api-tools-banner::

See also the :c:member:`PyTypeObject.tp_hash` member and :ref:`numeric-hash`.

.. c:type:: Py_hash_t
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/import.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Importing Modules
=================

.. c-api-tools-banner::


.. c:function:: PyObject* PyImport_ImportModule(const char *name)

Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Python/C API Reference Manual
##################################

.. c-api-tools-banner::

This manual documents the API used by C and C++ programmers who want to write
extension modules or embed Python. It is a companion to :ref:`extending-index`,
which describes the general principles of extension writing but does not
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Initialization, Finalization, and Threads
*****************************************

.. c-api-tools-banner::

See :ref:`Python Initialization Configuration <init-config>` for details
on how to configure the interpreter prior to initialization.

Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/init_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
Python Initialization Configuration
***********************************

.. c-api-tools-banner::


.. _pyinitconfig_api:

Expand Down
35 changes: 35 additions & 0 deletions Doc/c-api/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Introduction
************

.. c-api-tools-banner::

The Application Programmer's Interface to Python gives C and C++ programmers
access to the Python interpreter at a variety of levels. The API is equally
usable from C++, but for brevity it is generally referred to as the Python/C
Expand Down Expand Up @@ -844,3 +846,36 @@ after every statement run by the interpreter.)

Please refer to :file:`Misc/SpecialBuilds.txt` in the Python source distribution
for more detailed information.


.. _c-api-tools:

Recommended third party tools
=============================

The following third party tools offer both simpler and more sophisticated
approaches to creating C and C++ extensions for Python:

* `Cython <https://cython.org/>`_
* `cffi <https://cffi.readthedocs.io>`_
* `HPy <https://hpyproject.org/>`_
* `nanobind <https://github.com/wjakob/nanobind>`_ (C++)
* `Numba <https://numba.pydata.org/>`_
* `pybind11 <https://pybind11.readthedocs.io/>`_ (C++)
* `PyO3 <https://pyo3.rs/>`_ (Rust)
* `SWIG <https://www.swig.org>`_

Using tools such as these can help avoid writing code that is tightly bound to
a particular version of CPython, avoid reference counting errors, and focus
more on your own code than on using the CPython API. In general, new versions
of Python can be supported by updating the tool, and your code will often use
newer and more efficient APIs automatically. Some tools also support compiling
for other implementations of Python from a single set of sources.

Directly coding against the CPython C API should, in most cases, be your last
resort rather than the first.

These projects are not supported by the same people who maintain Python, and
issues need to be raised with the projects directly. Remember to check that the
project is still maintained and supported, as the list above may become
outdated.
2 changes: 2 additions & 0 deletions Doc/c-api/iter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Iterator Protocol
=================

.. c-api-tools-banner::

There are two functions specifically for working with iterators.

.. c:function:: int PyIter_Check(PyObject *o)
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/iterator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Iterator Objects
----------------

.. c-api-tools-banner::

Python provides two general-purpose iterator objects. The first, a sequence
iterator, works with an arbitrary sequence supporting the :meth:`~object.__getitem__`
method. The second works with a callable object and a sentinel value, calling
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ List Objects

.. index:: pair: object; list

.. c-api-tools-banner::


.. c:type:: PyListObject

Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/long.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Integer Objects
.. index:: pair: object; long integer
pair: object; integer

.. c-api-tools-banner::

All integers are implemented as "long" integer objects of arbitrary size.

On error, most ``PyLong_As*`` APIs return ``(return type)-1`` which cannot be
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/mapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Mapping Protocol
================

.. c-api-tools-banner::

See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
:c:func:`PyObject_DelItem`.

Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/marshal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Data marshalling support
========================

.. c-api-tools-banner::

These routines allow C code to work with serialized objects using the same
data format as the :mod:`marshal` module. There are functions to write data
into the serialization format, and additional functions that can be used to
Expand Down
Loading