]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Add docs for the psycopg module
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 12 Jul 2021 17:05:28 +0000 (19:05 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 12 Jul 2021 22:31:44 +0000 (00:31 +0200)
docs/api/adapt.rst
docs/api/errors.rst
docs/api/index.rst
docs/api/module.rst [new file with mode: 0644]

index c36ea540a614defad0d057bbedf85844b7ece52e..66f8ffbca86d9cf3dcaf11c068d388244be2f023 100644 (file)
@@ -51,15 +51,6 @@ Other objects used in adaptations
     :members:
 
 
-.. data:: psycopg.adapters
-
-   The global, default adapters map establishing how Python and PostgreSQL
-   types are converted into each other. This map is used as template when new
-   connections are created, using `psycopg.connect()`.
-
-   :type: `~psycopg.adapt.AdaptersMap`
-
-
 .. autoclass:: AdaptersMap
 
    .. automethod:: register_dumper
index 128dfbd7a0338739e8d06f6e6c53ea64ad79b3e4..4993357bd8ccfe42847890da1d1c377b1277cb76 100644 (file)
@@ -81,8 +81,8 @@ derive from the following classes:
             \|__ `ProgrammingError`
             \|__ `NotSupportedError`
 
-These classes are also exposed both by the Psycopg and the
-`!psycopg.errors` module.
+These classes are exposed both by the Psycopg and the `!psycopg.errors`
+module.
 
 .. autoexception:: Warning()
 .. autoexception:: InterfaceError()
@@ -107,8 +107,8 @@ SQLSTATE exceptions
 
 Errors coming from a database server (as opposite as ones generated
 client-side, such as connection failed) usually have a 5-letters error code
-called SQLSTATE (available in the `~Diagnostic.sqlstate` attribute of
-`Error.diag`).
+called SQLSTATE (available in the `~Diagnostic.sqlstate` attribute of the
+error's `~psycopg.Error.diag` attribute).
 
 Psycopg exposes a different class for each SQLSTATE value, allowing to
 write idiomatic error handling code according to specific conditions happening
@@ -126,8 +126,8 @@ classes for every error defined by PostgreSQL in versions between 9.6 and 13.
 Every class in the module is named after what referred as "condition name" `in
 the documentation`__, converted to CamelCase: e.g. the error 22012,
 ``division_by_zero`` is exposed by this module as the class `!DivisionByZero`.
-There is a handful of exception, required for disambiguate clashes: please
-refer to the table below for all the classes defined.
+There is a handful of... exceptions to this rule, required for disambiguate
+name clashes: please refer to the table below for all the classes defined.
 
 .. __: https://www.postgresql.org/docs/current/errcodes-appendix.html#ERRCODES-TABLE
 
index 44263f27289f78b12ce010460eaef0fb106357ca..6ff1e157ac8f8525a8559aece8c7ce5a11180657 100644 (file)
@@ -5,12 +5,13 @@ Psycopg 3 API
     :maxdepth: 2
     :caption: Contents:
 
+    module
     connections
     cursors
     sql
     errors
+    pool
     adapt
     types
     abc
-    pool
     pq
diff --git a/docs/api/module.rst b/docs/api/module.rst
new file mode 100644 (file)
index 0000000..aeb70b3
--- /dev/null
@@ -0,0 +1,52 @@
+The `!psycopg` module
+=====================
+
+Psycopg implements the `Python Database DB API 2.0 specification`__. As such
+it also exposes the `module-level objects`__ required by the specifications.
+
+.. __: https://www.python.org/dev/peps/pep-0249/
+.. __: https://www.python.org/dev/peps/pep-0249/#module-interface
+
+
+.. currentmodule:: psycopg
+
+.. autofunction:: connect
+
+   This is an alias of the class method `Connection.connect`: see its
+   documentation for details.
+
+   If you need an asynchronous connection use `AsyncConnection.connect`
+   instead.
+
+
+.. rubric:: Exceptions
+
+The standard `DBAPI exceptions`__ are exposed both by the `!psycopg` module
+and by the `psycopg.errors` module. The latter also exposes more specific
+exceptions, mapping to the database error states (see
+:ref:`sqlstate-exceptions`.
+
+.. __: https://www.python.org/dev/peps/pep-0249/#exceptions
+
+.. parsed-literal::
+
+    `!Exception`
+    \|__ `Warning`
+    \|__ `Error`
+        \|__ `InterfaceError`
+        \|__ `DatabaseError`
+            \|__ `DataError`
+            \|__ `OperationalError`
+            \|__ `IntegrityError`
+            \|__ `InternalError`
+            \|__ `ProgrammingError`
+            \|__ `NotSupportedError`
+
+
+.. data:: adapters
+
+   The global, default adapters map establishing how Python and PostgreSQL
+   types are converted into each other. This map is used as template when new
+   connections are created, using `psycopg.connect()`.
+
+   :type: `~psycopg.adapt.AdaptersMap`