extras.postgresql — PostgreSQL Database Service¶
A YellowService for running PostGreSQL DB. Runs the official PostgreSQL docker image, with
integration with sqlalchemy.
Note
Requires the postgresql extra. For more information, see our installation guide.
- class extras.postgresql.PostgreSQLService(docker_client: DockerClient, image: str = 'postgres:latest', *, user: str = 'postgres', password: str = 'guest', default_db: str | None = None, container_create_kwargs: dict[str, Any] | None = None, **kwargs)[source]¶
A service that runs a PostgreSQL database. Inherits from
SingleContainerServiceandSQLService.- Parameters:
docker_client – The docker client to used to pull and create the Postgresql container.
image – The image name to create a container of.
user – The name of the default user for the database.
password – The password for the default user.
default_db – The name of the default database. If
None, uses the same name as the default user.container_create_kwargs – Additional keyword arguments passed to
docker.models.containers.ContainerCollection.create().**kwargs – Additional keyword arguments passed to
SQLService.
Has the following additional methods:
- local_connection_string(...) str[source]¶
- container_connection_string(...) str[source]¶
- host_connection_string(...) str[source]¶
Equivalent to
SQLService.local_connection_string(),SQLService.container_connection_string(), andSQLService.host_connection_string(), except that the database parameter defaults to the default_db
- engine(**kwargs) Engine[source]¶
Deprecated since version 0.7.2: Create an engine manually instead.
Returns a sqlalchemy engine to the database, using a default connection string generated by
local_connection_string().- Parameters:
**kwargs – Additional keyword arguments passed to
sqlalchemy.create_engine().
- connection(**kwargs) Connection[source]¶
Deprecated since version 0.7.2: Create a connection from a manually-created engine instead.
Creates an SQLAlchemy connection to the database, using a default connection string generated by
local_connection_string().- Parameters:
**kwargs – Additional keyword arguments passed to
sqlalchemy.Engine.connect().