Examples
These examples illustrate the ways in which OpenAPI programming in Python differs from using C. They are presented in no particular order.
For comprehensive instruction in the workings of the OpenAPI refer to the OpenAPI User Guide.
Most of the examples here are only illustrative fragments of code, not complete applications. See Hello Pyngres for an example of a complete but trivial application that can be used as a starting point for experimentation.
Note
Basic knowledge of asyncio is assumed for some of the examples.
Tip
The usefulness of asyncio is hard to overstate. Every Python
programmer would benefit from familiarity with it. One excellent resource
is Python Asyncio: The Complete Guide, maintained
by Jason Brownlee. The content is also available as a book entitled
Python Asyncio Jump-Start, ISBN-13: 979-8361197620.
Contents:
- Connecting to a Database (Synchronously)
- Connecting to a Database (Asynchronously)
- Setting Up Data Buffers
- Handling VARCHAR and VARBYTE Data
- Handling Date Data
- Execute an SQL Statement (No Parameters, No Result Rows)
- Execute a Parameterized SQL Statement
- Execute a SELECT Statement Returning Row(s)
- Fetching Error Information
- Using Callbacks
- Setting Up Tracing
- Catching DBEvents