summaryrefslogtreecommitdiffstats
path: root/Doc/c-api/init_config.rst
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-09-02 21:25:08 (GMT)
committerGitHub <noreply@github.com>2024-09-02 21:25:08 (GMT)
commit33b790978d8b817a66a4a117a8c38a857b6103f0 (patch)
treeea11817b7267715e2b19e944e42233c7a4a28399 /Doc/c-api/init_config.rst
parentdb42934270c5c23be9f6804cad98dfd8234caf6f (diff)
downloadcpython-33b790978d8b817a66a4a117a8c38a857b6103f0.zip
cpython-33b790978d8b817a66a4a117a8c38a857b6103f0.tar.gz
cpython-33b790978d8b817a66a4a117a8c38a857b6103f0.tar.bz2
gh-107954, PEP 741: Add PyConfig_Get()/Set() functions (#123472)
Add PyConfig_Get(), PyConfig_GetInt(), PyConfig_Set() and PyConfig_Names() functions to get and set the current runtime Python configuration. Add visibility and "sys spec" to config and preconfig specifications. _PyConfig_AsDict() now converts PyConfig.xoptions as a dictionary. Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Diffstat (limited to 'Doc/c-api/init_config.rst')
-rw-r--r--Doc/c-api/init_config.rst69
1 files changed, 69 insertions, 0 deletions
diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst
index 6e2e04f..355b8e0 100644
--- a/Doc/c-api/init_config.rst
+++ b/Doc/c-api/init_config.rst
@@ -1605,6 +1605,75 @@ customized Python always running in isolated mode using
:c:func:`Py_RunMain`.
+Runtime Python configuration API
+================================
+
+The configuration option *name* parameter must be a non-NULL null-terminated
+UTF-8 encoded string.
+
+Some options are read from the :mod:`sys` attributes. For example, the option
+``"argv"`` is read from :data:`sys.argv`.
+
+
+.. c:function:: PyObject* PyConfig_Get(const char *name)
+
+ Get the current runtime value of a configuration option as a Python object.
+
+ * Return a new reference on success.
+ * Set an exception and return ``NULL`` on error.
+
+ The object type depends on the configuration option. It can be:
+
+ * ``bool``
+ * ``int``
+ * ``str``
+ * ``list[str]``
+ * ``dict[str, str]``
+
+ The caller must hold the GIL. The function cannot be called before
+ Python initialization nor after Python finalization.
+
+ .. versionadded:: 3.14
+
+
+.. c:function:: int PyConfig_GetInt(const char *name, int *value)
+
+ Similar to :c:func:`PyConfig_Get`, but get the value as a C int.
+
+ * Return ``0`` on success.
+ * Set an exception and return ``-1`` on error.
+
+ .. versionadded:: 3.14
+
+
+.. c:function:: PyObject* PyConfig_Names(void)
+
+ Get all configuration option names as a ``frozenset``.
+
+ * Return a new reference on success.
+ * Set an exception and return ``NULL`` on error.
+
+ The caller must hold the GIL. The function cannot be called before
+ Python initialization nor after Python finalization.
+
+ .. versionadded:: 3.14
+
+
+.. c:function:: int PyConfig_Set(const char *name, PyObject *value)
+
+ Set the current runtime value of a configuration option.
+
+ * Raise a :exc:`ValueError` if there is no option *name*.
+ * Raise a :exc:`ValueError` if *value* is an invalid value.
+ * Raise a :exc:`ValueError` if the option is read-only (cannot be set).
+ * Raise a :exc:`TypeError` if *value* has not the proper type.
+
+ The caller must hold the GIL. The function cannot be called before
+ Python initialization nor after Python finalization.
+
+ .. versionadded:: 3.14
+
+
Py_GetArgcArgv()
================