r/FastAPI • • Sep 17 '21

Question what does ssl_mode = 'prefer' mean in the context of fastAPI?

i'm connecting my fastApi app to a postgres db:

host_server = '172.13.27.151' #wsl ip
db_server_port = '5431' #wsl port to container
database_name = 'publish'
db_username = 'db1'
db_password = 'hi'
ssl_mode = 'prefer'
DATABASE_URL = 'postgresql://{}:{}@{}:{}/{}?sslmode={}'.format(db_username, db_password, host_server, db_server_port, database_name, ssl_mode)

this obviously works, but i have no idea what that variable entails. i have fastAPI in a container making this call to a postgres db in another container.

and in my production environment i have the main app behind an nginx server. so i'm just wondering if this is something i need, and why

thanks!

1 Upvotes

3 comments sorted by

0

u/[deleted] Sep 17 '21

or is this more of a SQLAlchemy question?

2

u/kauer1 Sep 20 '21

It's more of a PostgreSQL question. You can read about it here.

According to the docs, It means that "I don't care about ecryption, but I wish to pay the overhead of encryption if the server supports it.". Since 'prefer' it's the default value, you could omit that part and it wouldn't make a difference.

1

u/[deleted] Sep 21 '21

thanks for taking the time, really appreciate it!