Skip to content

Commit e8d3027

Browse files
committed
docs: add docstrings for methods directly used methods
1 parent 1ff2a98 commit e8d3027

10 files changed

+322
-19
lines changed

redshift_connector/__init__.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,85 @@ def connect(
121121
role_session_name: typing.Optional[str] = None,
122122
role_arn: typing.Optional[str] = None,
123123
) -> Connection:
124+
"""
125+
Establishes a :class:`Connection` to an Amazon Redshift cluster. This function validates user input, optionally authenticates using an identity provider plugin, then constructs a :class:`Connection` object.
124126
127+
Parameters
128+
----------
129+
user : str
130+
The username to use for authentication with the Amazon Redshift cluster.
131+
password : str
132+
The password to use for authentication with the Amazon Redshift cluster.
133+
database : str
134+
The name of the database instance to connect to.
135+
host : str
136+
The hostname of the Amazon Redshift cluster.
137+
port : int
138+
The port number of the Amazon Redshift cluster. Default value is 5439.
139+
source_address : typing.Optional[str]
140+
unix_sock : Optional[str]
141+
ssl : bool
142+
Is SSL enabled. Default value is ``True``. SSL must be enabled when authenticating using IAM.
143+
sslmode : str
144+
The security of the connection to the Amazon Redshift cluster. 'verify-ca' and 'verify-full' are supported.
145+
timeout : Optional[int]
146+
The number of seconds before the connection to the server will timeout. By default there is no timeout.
147+
max_prepared_statements : int
148+
tcp_keepalive : Optional[bool]
149+
Is `TCP keepalive <https://en.wikipedia.org/wiki/Keepalive#TCP_keepalive>`_ used. The default value is ``True``.
150+
application_name : Optional[str]
151+
Sets the application name. The default value is None.
152+
replication : Optional[str]
153+
Used to run in `streaming replication mode <https://www.postgresql.org/docs/12/protocol-replication.html>`_.
154+
idp_host : Optional[str]
155+
The hostname of the IdP.
156+
db_user : str
157+
The user ID to use with Amazon Redshift
158+
app_id : Optional[str]
159+
app_name : str
160+
The name of the identity provider (IdP) application used for authentication.
161+
preferred_role : str
162+
The IAM role preferred for the current connection.
163+
principal_arn : Optional[str]
164+
credentials_provider : str
165+
The class name of the IdP that will be used for authenticating with the Amazon Redshift cluster.
166+
region : str
167+
The AWS region where the Amazon Redshift cluster is located.
168+
cluster_identifier : str
169+
The cluster identifier of the Amazon Redshift cluster.
170+
iam : bool
171+
If IAM authentication is enabled. Default value is False. IAM must be True when authenticating using an IdP.
172+
client_id : str
173+
The client id from Azure IdP.
174+
idp_tenant : str
175+
The IdP tenant.
176+
client_secret : str
177+
The client secret from Azure IdP.
178+
partner_sp_id : Optional[str]
179+
idp_response_timeout : int
180+
The timeout for retrieving SAML assertion from IdP. Default value is `120`.
181+
listen_port : int
182+
The listen port the IdP will send the SAML assertion to. Default value is `7890`.
183+
login_url : str
184+
The SSO url for the IdP.
185+
auto_create :bool
186+
Indicates whether the user should be created if they do not exist. Default value is `False`.
187+
db_groups : str
188+
A comma-separated list of existing database group names that the `db_user` joins for the current session.
189+
force_lowercase :
190+
allow_db_user_override : bool
191+
Specifies if the driver uses the `db_user` value from the SAML assertion. TDefault value is `False`.
192+
client_protocol_version : int
193+
The requested server protocol version. The default value is 1 representing `EXTENDED_RESULT_METADATA`. If the requested server protocol cannot be satisfied, a warning will be displayed to the user.
194+
database_metadata_current_db_only : bool
195+
Is `datashare <https://docs.aws.amazon.com/redshift/latest/dg/datashare-overview.html>`_ disabled. Default value is True, implying datasharing will not be used.
196+
ssl_insecure : bool
197+
Specifies if IdP host's server certificate will be verified. Default value is True
198+
199+
Returns
200+
-------
201+
A Connection object associated with the specified Amazon Redshift cluster: :class:`Connection`
202+
"""
125203
info: RedshiftProperty = RedshiftProperty()
126204
IamHelper.set_iam_properties(
127205
info,
@@ -209,6 +287,9 @@ def connect(
209287
"""
210288

211289
paramstyle: str = "format"
290+
"""
291+
String property stating the type of parameter marker formatting expected by the interface; This value defaults to "format", in which parameters are marked in this format "WHERE name=%s"
292+
"""
212293

213294
# I have no idea what this would be used for by a client app. Should it be
214295
# TEXT, VARCHAR, CHAR? It will only compare against row_description's
@@ -259,4 +340,5 @@ def connect(
259340
"PGTsvector",
260341
"PGText",
261342
"PGVarchar",
343+
"__version__",
262344
]

redshift_connector/core.py

Lines changed: 101 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,42 @@ def __init__(
366366
client_protocol_version: int = DEFAULT_PROTOCOL_VERSION,
367367
database_metadata_current_db_only: bool = True,
368368
):
369-
369+
"""
370+
Creates a :class:`Connection` to an Amazon Redshift cluster. For more information on establishing a connection to an Amazon Redshift cluster using `federated API access <https://aws.amazon.com/blogs/big-data/federated-api-access-to-amazon-redshift-using-an-amazon-redshift-connector-for-python/>`_ see our examples page.
371+
This is the underlying :class:`Connection` constructor called from :func:`redshift_connector.connect`.
372+
373+
Parameters
374+
----------
375+
user : str
376+
The username to use for authentication with the Amazon Redshift cluster.
377+
password : str
378+
The password to use for authentication with the Amazon Redshift cluster.
379+
database : str
380+
The name of the database instance to connect to.
381+
host : str
382+
The hostname of the Amazon Redshift cluster.
383+
port : int
384+
The port number of the Amazon Redshift cluster. Default value is 5439.
385+
source_address : Optional[str]
386+
unix_sock : Optional[str]
387+
ssl : bool
388+
Is SSL enabled. Default value is ``True``. SSL must be enabled when authenticating using IAM.
389+
sslmode : str
390+
The security of the connection to the Amazon Redshift cluster. 'verify-ca' and 'verify-full' are supported.
391+
timeout : Optional[int]
392+
The number of seconds before the connection to the server will timeout. By default there is no timeout.
393+
max_prepared_statements : int
394+
tcp_keepalive : Optional[bool]
395+
Is `TCP keepalive <https://en.wikipedia.org/wiki/Keepalive#TCP_keepalive>`_ used. The default value is ``True``.
396+
application_name : Optional[str]
397+
Sets the application name. The default value is None.
398+
replication : Optional[str]
399+
Used to run in `streaming replication mode <https://www.postgresql.org/docs/12/protocol-replication.html>`_.
400+
client_protocol_version : int
401+
The requested server protocol version. The default value is 1 representing `EXTENDED_RESULT_METADATA`. If the requested server protocol cannot be satisfied, a warning will be displayed to the user.
402+
database_metadata_current_db_only : bool
403+
Is `datashare <https://docs.aws.amazon.com/redshift/latest/dg/datashare-overview.html>`_ disabled. Default value is True, implying datasharing will not be used.
404+
"""
370405
self.merge_socket_read = False
371406

372407
_client_encoding = "utf8"
@@ -684,14 +719,25 @@ def cursor(self: "Connection") -> Cursor:
684719
685720
This function is part of the `DBAPI 2.0 specification
686721
<http://www.python.org/dev/peps/pep-0249/>`_.
722+
723+
Returns
724+
-------
725+
A Cursor object associated with the current Connection: :class:`Cursor`
687726
"""
688727
return Cursor(self)
689728

690729
@property
691730
def description(self: "Connection") -> typing.Optional[typing.List]:
692731
return self._run_cursor._getDescription()
693732

694-
def run(self: "Connection", sql, stream=None, **params):
733+
def run(self: "Connection", sql, stream=None, **params) -> typing.Tuple[typing.Any, ...]:
734+
"""
735+
Executes an sql statement, and returns the results as a `tuple`.
736+
737+
Returns
738+
-------
739+
Result of executing an sql statement:tuple[Any, ...]
740+
"""
695741
self._run_cursor.execute(sql, params, stream=stream)
696742
return tuple(self._run_cursor._cached_rows)
697743

@@ -700,6 +746,10 @@ def commit(self: "Connection") -> None:
700746
701747
This function is part of the `DBAPI 2.0 specification
702748
<http://www.python.org/dev/peps/pep-0249/>`_.
749+
750+
Returns
751+
-------
752+
None:None
703753
"""
704754
self.execute(self._cursor, "commit", None)
705755

@@ -708,6 +758,10 @@ def rollback(self: "Connection") -> None:
708758
709759
This function is part of the `DBAPI 2.0 specification
710760
<http://www.python.org/dev/peps/pep-0249/>`_.
761+
762+
Returns
763+
-------
764+
None:None
711765
"""
712766
if not self.in_transaction:
713767
return
@@ -718,6 +772,10 @@ def close(self: "Connection") -> None:
718772
719773
This function is part of the `DBAPI 2.0 specification
720774
<http://www.python.org/dev/peps/pep-0249/>`_.
775+
776+
Returns
777+
-------
778+
None:None
721779
"""
722780
try:
723781
# Byte1('X') - Identifies the message as a terminate message.
@@ -908,6 +966,19 @@ def handle_ROW_DESCRIPTION(self: "Connection", data, cursor: Cursor) -> None:
908966
field["pg8000_fc"], field["func"] = pg_types[field["type_oid"]]
909967

910968
def execute(self: "Connection", cursor: Cursor, operation: str, vals) -> None:
969+
"""
970+
Executes a database operation. Parameters may be provided as a sequence, or as a mapping, depending upon the value of `redshift_connector.paramstyle`.
971+
972+
Parameters
973+
----------
974+
cursor : :class:`Cursor`
975+
operation : str The SQL statement to execute.
976+
vals : If `redshift_connector.paramstyle` is `qmark`, `numeric`, or `format` this argument should be an array of parameters to bind into the statement. If `redshift_connector.paramstyle` is `named` the argument should be a `dict` mapping of parameters. If `redshift_connector.paramstyle` is `pyformat`, the argument value may be either an array or mapping.
977+
978+
Returns
979+
-------
980+
None:None
981+
"""
911982
if vals is None:
912983
vals = ()
913984

@@ -1332,12 +1403,16 @@ def send_array(arr: typing.List) -> typing.Union[bytes, bytearray]:
13321403

13331404
return (array_oid, fc, send_array)
13341405

1335-
def xid(self: "Connection", format_id, global_transaction_id, branch_qualifier):
1406+
def xid(self: "Connection", format_id, global_transaction_id, branch_qualifier) -> typing.Tuple:
13361407
"""Create a Transaction IDs (only global_transaction_id is used in pg)
13371408
format_id and branch_qualifier are not used in postgres
13381409
global_transaction_id may be any string identifier supported by
1339-
postgres returns a tuple
1340-
(format_id, global_transaction_id, branch_qualifier)"""
1410+
postgres.
1411+
1412+
Returns
1413+
-------
1414+
(format_id, global_transaction_id, branch_qualifier):typing.Tuple
1415+
"""
13411416
return (format_id, global_transaction_id, branch_qualifier)
13421417

13431418
def tpc_begin(self: "Connection", xid) -> None:
@@ -1352,6 +1427,10 @@ def tpc_begin(self: "Connection", xid) -> None:
13521427
13531428
This function is part of the `DBAPI 2.0 specification
13541429
<http://www.python.org/dev/peps/pep-0249/>`_.
1430+
1431+
Returns
1432+
-------
1433+
None:None
13551434
"""
13561435
self._xid = xid
13571436
if self.autocommit:
@@ -1367,6 +1446,10 @@ def tpc_prepare(self: "Connection") -> None:
13671446
13681447
This function is part of the `DBAPI 2.0 specification
13691448
<http://www.python.org/dev/peps/pep-0249/>`_.
1449+
1450+
Returns
1451+
-------
1452+
None:None
13701453
"""
13711454
if self._xid is None or len(self._xid) < 2:
13721455
raise InterfaceError("Malformed Transaction Id")
@@ -1391,6 +1474,10 @@ def tpc_commit(self: "Connection", xid=None) -> None:
13911474
13921475
This function is part of the `DBAPI 2.0 specification
13931476
<http://www.python.org/dev/peps/pep-0249/>`_.
1477+
1478+
Returns
1479+
-------
1480+
None:None
13941481
"""
13951482
if xid is None:
13961483
xid = self._xid
@@ -1423,6 +1510,10 @@ def tpc_rollback(self: "Connection", xid=None) -> None:
14231510
14241511
This function is part of the `DBAPI 2.0 specification
14251512
<http://www.python.org/dev/peps/pep-0249/>`_.
1513+
1514+
Returns
1515+
-------
1516+
None:None
14261517
"""
14271518
if xid is None:
14281519
xid = self._xid
@@ -1443,12 +1534,16 @@ def tpc_rollback(self: "Connection", xid=None) -> None:
14431534
self.autocommit = previous_autocommit_mode
14441535
self._xid = None
14451536

1446-
def tpc_recover(self: "Connection"):
1537+
def tpc_recover(self: "Connection") -> typing.List[typing.Tuple[typing.Any, ...]]:
14471538
"""Returns a list of pending transaction IDs suitable for use with
14481539
.tpc_commit(xid) or .tpc_rollback(xid).
14491540
14501541
This function is part of the `DBAPI 2.0 specification
14511542
<http://www.python.org/dev/peps/pep-0249/>`_.
1543+
1544+
Returns
1545+
-------
1546+
List of pending transaction IDs:List[tuple[Any, ...]]
14521547
"""
14531548
try:
14541549
previous_autocommit_mode: bool = self.autocommit

0 commit comments

Comments
 (0)