{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "dev:depending_on_numpy",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This document aims to explain some best practices for authoring a package that depends on NumPy."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "For downstream package authors"
        }
      ],
      "level": 0,
      "target": "for-downstream-package-authors"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "NumPy uses a standard, "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Pep 440"
                }
              ],
              "url": "https://peps.python.org/pep-0440/",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " compliant, versioning scheme: "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "major.minor.bugfix"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". A "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "major"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " release is highly unusual and if it happens it will most likely indicate an ABI break. NumPy 1.xx releases happened from 2006 to 2023; NumPy 2.0 in early 2024 is the first release which changed the ABI (minor ABI breaks for corner cases may have happened a few times in minor releases). "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Minor"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " versions are released regularly, typically every 6 months. Minor versions contain new features, deprecations, and removals of previously deprecated code. "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Bugfix"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " releases are made even more frequently; they do not contain any new features or deprecations."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "It is important to know that NumPy, like Python itself and most other well known scientific Python projects, does "
            },
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "not"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " use semantic versioning. Instead, backwards incompatible API changes require deprecation warnings for at least two releases. For more details, see "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "NEP23",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "NumPy provides both a Python API and a C-API. The C-API can be accessed directly or through tools like Cython or f2py. If your package uses the C-API, it's important to understand NumPy's application binary interface (ABI) compatibility: NumPy's ABI is forward compatible but not backward compatible. This means that binaries compiled against an older version of NumPy will still work with newer versions, but binaries compiled against a newer version will not necessarily work with older ones."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Modules can also be safely built against NumPy 2.0 or later in "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "CPython's abi3 mode <python:stable-abi>",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", which allows building against a single (minimum-supported) version of Python but be forward compatible higher versions in the same series (e.g., "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "3.x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "). This can greatly reduce the number of wheels that need to be built and distributed. For more information and examples, see the "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "cibuildwheel docs"
                }
              ],
              "url": "https://cibuildwheel.pypa.io/en/stable/faq/#abi3",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Understanding NumPy's versioning and API/ABI stability"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For large, actively maintained packages that depend on NumPy, we recommend testing against the development version of NumPy in CI. To make this easy, nightly builds are provided as wheels at https://anaconda.org/scientific-python-nightly-wheels/. Example install command      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "pip install -U --pre --only-binary :all: -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This helps detect regressions in NumPy that need fixing before the next NumPy release.  Furthermore, we recommend to raise errors on warnings in CI for this job, either all warnings or otherwise at least "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "DeprecationWarning"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "FutureWarning"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". This gives you an early warning about changes in NumPy to adapt your code."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If you want to test your own wheel builds against the latest NumPy nightly build and you're using "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "cibuildwheel"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", you may need something like this in your CI config file:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "CIBW_ENVIRONMENT: \"PIP_PRE=1 PIP_EXTRA_INDEX_URL=https://pypi.anaconda.org/scientific-python-nightly-wheels/simple\"",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Testing against the NumPy main branch or pre-releases"
        }
      ],
      "level": 1,
      "target": "testing-prereleases"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Adding a dependency on NumPy"
        }
      ],
      "level": 1,
      "target": "depending_on_numpy"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Before NumPy 1.25, the NumPy C-API was "
                },
                {
                  "__type": "Emphasis",
                  "__tag": 4047,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "not"
                    }
                  ]
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " exposed in a backwards compatible way by default. This means that when compiling with a NumPy version earlier than 1.25 you have to compile with the oldest version you wish to support. This can be done by using "
                },
                {
                  "__type": "Link",
                  "__tag": 4049,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "oldest-supported-numpy"
                    }
                  ],
                  "url": "https://github.com/scipy/oldest-supported-numpy/",
                  "title": ""
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ". Please see the "
                },
                {
                  "__type": "Link",
                  "__tag": 4049,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "NumPy 1.24 documentation"
                    }
                  ],
                  "url": "https://numpy.org/doc/1.24/dev/depending_on_numpy.html",
                  "title": ""
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If a package either uses the NumPy C-API directly or it uses some other tool that depends on it like Cython or Pythran, NumPy is a "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "build-time"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " dependency of the package."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "By default, NumPy exposes an API that is backward compatible with the earliest NumPy version that supports the oldest Python version currently supported by NumPy. For example, NumPy 1.25.0 supports Python 3.9 and above; and the earliest NumPy version to support Python 3.9 was 1.19. Therefore we guarantee NumPy 1.25 will, when using defaults, expose a C-API compatible with NumPy 1.19. (the exact version is set within NumPy-internal header files)."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "NumPy is also forward compatible for all minor releases, but a major release will require recompilation (see NumPy 2.0-specific advice further down)."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The default behavior can be customized for example by adding      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "#define NPY_TARGET_VERSION NPY_1_22_API_VERSION",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "before including any NumPy headers (or the equivalent "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "-D"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " compiler flag) in every extension module that requires the NumPy C-API. This is mainly useful if you need to use newly added API at the cost of not being compatible with older versions."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If for some reason you wish to compile for the currently installed NumPy version by default you can add      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "#ifndef NPY_TARGET_VERSION\n    #define NPY_TARGET_VERSION NPY_API_VERSION\n#endif",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Which allows a user to override the default via "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "-DNPY_TARGET_VERSION"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". This define must be consistent for each extension module (use of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "import_array()"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") and also applies to the umath module."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When you compile against NumPy, you should add the proper version restrictions to your "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "pyproject.toml"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (see PEP 517).  Since your extension will not be compatible with a new major release of NumPy and may not be compatible with very old versions."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For conda-forge packages, please see "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "here"
                }
              ],
              "url": "https://conda-forge.org/docs/maintainer/knowledge_base.html#building-against-numpy",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for instructions on how to declare a dependency on "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "numpy"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " when using the C API."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Build-time dependency"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "NumPy itself and many core scientific Python packages have agreed on a schedule for dropping support for old Python and NumPy versions: "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "NEP29",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". We recommend all packages depending on NumPy to follow the recommendations in NEP 29."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "run-time dependencies"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", specify version bounds using "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "install_requires"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " in "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "setup.py"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (assuming you use "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "numpy.distutils"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "setuptools"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to build)."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Most libraries that rely on NumPy will not need to set an upper version bound: NumPy is careful to preserve backward-compatibility."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "That said, if you are (a) a project that is guaranteed to release frequently, (b) use a large part of NumPy's API surface, and (c) is worried that changes in NumPy may break your code, you can set an upper bound of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "<MAJOR.MINOR + N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " with N no less than 3, and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "MAJOR.MINOR"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " being the current release of NumPy "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "*"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". If you use the NumPy C-API (directly or via Cython), you can also pin the current major version to prevent ABI breakage. Note that setting an upper bound on NumPy may "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "affect the ability of your library to be installed alongside other, newer packages"
                }
              ],
              "url": "https://iscinumpy.dev/post/bound-version-constraints/",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Footnote",
          "__tag": 4067,
          "label": "*",
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "The reason for setting "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "N=3"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " is that NumPy will, on the        rare occasion where it makes breaking changes, raise warnings        for at least two releases. (NumPy releases about once every six        months, so this translates to a window of at least a year;        hence the subsequent requirement that your project releases at        least on that cadence.)"
                }
              ]
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "SciPy has more documentation on how it builds wheels and deals with its build-time and runtime dependencies "
                },
                {
                  "__type": "Link",
                  "__tag": 4049,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "here"
                    }
                  ],
                  "url": "https://scipy.github.io/devdocs/dev/core-dev/index.html#distributing",
                  "title": ""
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "."
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "NumPy and SciPy wheel build CI may also be useful as a reference, it can be found "
                },
                {
                  "__type": "Link",
                  "__tag": 4049,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "here for NumPy"
                    }
                  ],
                  "url": "https://github.com/MacPython/numpy-wheels",
                  "title": ""
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " and "
                },
                {
                  "__type": "Link",
                  "__tag": 4049,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "here for SciPy"
                    }
                  ],
                  "url": "https://github.com/MacPython/scipy-wheels",
                  "title": ""
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "."
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Runtime dependency & version ranges"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "NumPy 2.0 is an ABI-breaking release, however it does contain support for building wheels that work on both 2.0 and 1.xx releases. It's important to understand that:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": true,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "When you build wheels for your package using a NumPy 1.xx version at build    time, those "
                    },
                    {
                      "__type": "Strong",
                      "__tag": 4048,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "will not work"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " with NumPy 2.0."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "When you build wheels for your package using a NumPy 2.x version at build    time, those "
                    },
                    {
                      "__type": "Strong",
                      "__tag": 4048,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "will work"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " with NumPy 1.xx."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The first time the NumPy ABI for 2.0 is guaranteed to be stable will be the release of the first release candidate for 2.0 (i.e., 2.0.0rc1). Our advice for handling your dependency on NumPy is as follows:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": true,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "In the main (development) branch of your package, do not add any constraints."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If you rely on the NumPy C-API (e.g. via direct use in C/C++, or via Cython    code that uses NumPy), add a "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "numpy<2.0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " requirement in your    package's dependency metadata for releases / in release branches. Do this    until numpy "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "2.0.0rc1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is released and you can target that.    "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "Rationale: the NumPy C ABI will change in 2.0, so any compiled extension\n   modules that rely on NumPy will break; they need to be recompiled."
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If you rely on a large API surface from NumPy's Python API, also consider    adding the same "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "numpy<2.0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " requirement to your metadata until you are    sure your code is updated for changes in 2.0 (i.e., when you've tested    things work against "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "2.0.0rc1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ").    "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "Rationale: we will do a significant API cleanup, with many aliases and\n   deprecated/non-recommended objects being removed (see, e.g.,"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "    "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy-2-migration-guide",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "numpy_2_0_migration_guide"
                      },
                      "kind": "exists"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "and"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "NEP52",
                      "domain": null,
                      "role": "ref",
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "), "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "so unless you only use\n   modern/recommended functions and objects, your code is likely to require at\n   least some adjustments."
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Plan to do a release of your own packages which depend on "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "numpy"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " shortly    after the first NumPy 2.0 release candidate is released (probably around 1    Feb 2024).    "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "Rationale: at that point, you can release packages that will work with both\n   2.0 and 1.X, and hence your own end users will not be seeing much/any\n   disruption (you want"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "pip install mypackage"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "to continue working on the\n   day NumPy 2.0 is released)."
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Once "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "2.0.0rc1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is available, you can adjust your metadata in    "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "pyproject.toml"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " in the way outlined below."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There are two cases: you need to keep compatibility with numpy 1.xx while also supporting 2.0, or you are able to drop numpy 1.xx support for new releases of your package and support >=2.0 only. The latter is simpler, but may be more restrictive for your users. In that case, simply add "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "numpy>=2.0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (or "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "numpy>=2.0.0rc1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") to your build and runtime requirements and you're good to go. We'll focus on the \"keep compatibility with 1.xx and 2.x\" now, which is a little more involved."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Example for a package using the NumPy C-API (via C/Cython/etc.) which wants to support\nNumPy 1.23.5 and up"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "[build-system]\nbuild-backend = ...\nrequires = [\n    # Note for packagers: this constraint is specific to wheels\n    # for PyPI; it is also supported to build against 1.xx still.\n    # If you do so, please ensure to include a `numpy<2.0`\n    # runtime requirement for those binary packages.\n    \"numpy>=2.0.0rc1\",\n    ...\n]\n\n[project]\ndependencies = [\n    \"numpy>=1.23.5\",\n]",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "We recommend that you have at least one CI job which builds/installs via a wheel, and then runs tests against the oldest numpy version that the package supports. For example:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "- name: Build wheel via wheel, then install it\n  run: |\n    python -m build  # This will pull in numpy 2.0 in an isolated env\n    python -m pip install dist/*.whl\n\n- name: Test against oldest supported numpy version\n  run: |\n    python -m pip install numpy==1.23.5\n    # now run test suite",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The above only works once NumPy 2.0 is available on PyPI. If you want to test against a NumPy 2.0-dev wheel, you have to use a numpy nightly build (see "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "this section",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "dev:depending_on_numpy"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " higher up) or build numpy from source."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "NumPy 2.0-specific advice"
        }
      ],
      "level": 2,
      "target": "numpy-2-abi-handling"
    }
  ],
  "local_refs": []
}