conninfo
– manipulate connection strings#
This module contains a few utility functions to manipulate database connection strings.
- psycopg.conninfo.conninfo_to_dict(conninfo: str = '', **kwargs: Optional[Union[str, int]]) dict[str, Union[str, int, NoneType]] #
Convert the
conninfo
string into a dictionary of parameters.- Parameters:
conninfo – A connection string as accepted by PostgreSQL.
kwargs – Parameters overriding the ones specified in
conninfo
.
- Returns:
Dictionary with the parameters parsed from
conninfo
andkwargs
.
Raise
ProgrammingError
ifconninfo
is not a a valid connection string.>>> conninfo_to_dict("postgres://jeff@example.com/db", user="piro") {'user': 'piro', 'dbname': 'db', 'host': 'example.com'}
- psycopg.conninfo.make_conninfo(conninfo: str = '', **kwargs: Optional[Union[str, int]]) str #
Merge a string and keyword params into a single conninfo string.
- Parameters:
conninfo – A connection string as accepted by PostgreSQL.
kwargs – Parameters overriding the ones specified in
conninfo
.
- Returns:
A connection string valid for PostgreSQL, with the
kwargs
parameters merged.
Raise
ProgrammingError
if the input doesn’t make a valid conninfo string.>>> make_conninfo("dbname=db user=jeff", user="piro", port=5432) 'dbname=db user=piro port=5432'