Pydantic: Allow driver in postgresdsn

Created on 14 Nov 2020  路  4Comments  路  Source: samuelcolvin/pydantic

Checks

  • [x] I added a descriptive title to this issue
  • [x] I have searched (google, github) for similar issues and couldn't find anything
  • [x] I have read and followed the docs and still think this feature/change is needed
  • [x] After submitting this, I commit to one of:

    • Look through open issues and helped at least one other person

    • Hit the "watch" button on this repo to receive notifications and I commit to help at least 2 people that ask questions in the future

    • Implement a Pull Request for a confirmed bug

Feature Request

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.7.2
            pydantic compiled: True
                 install path: /home/sebastiannl/.local/lib/python3.8/site-packages/pydantic
               python version: 3.8.6 (default, Sep 30 2020, 04:00:38)  [GCC 10.2.0]
                     platform: Linux-5.8.18-1-MANJARO-x86_64-with-glibc2.2.5
     optional deps. installed: ['typing-extensions', 'email-validator']

currently its impossible to define a driver for a postgresdsn since only {'postgres', 'postgresql'} are allowed schemes. i think it should be possible to use "postgressql+asyncpg", too.

from pydantic import PostgresDsn

postgres = PostgresDsn.build(
            scheme="postgresql+asyncpg",
            user=values.get("POSTGRES_USER"),
            password=values.get("POSTGRES_PASSWORD"),
            host=values.get("POSTGRES_SERVER"),
            path=f"/{values.get('POSTGRES_DB') or ''}",
        )

feature request

Most helpful comment

There are other instances of +something in a URI scheme (git+https comes to mind, as does mongodb+srv from here. Perhaps it would be useful to add to the regex to grab a separate scheme_extra value?
Mainly I think it would be imprudent to try to enumerate all the possible postgres drivers (or other combinations of extra schemes) in Pydantic, so some flexibility here might be warranted.
Maybe an extra_scheme_allowed: bool flag on AnyUrl, defaulting to False?

All 4 comments

There are other instances of +something in a URI scheme (git+https comes to mind, as does mongodb+srv from here. Perhaps it would be useful to add to the regex to grab a separate scheme_extra value?
Mainly I think it would be imprudent to try to enumerate all the possible postgres drivers (or other combinations of extra schemes) in Pydantic, so some flexibility here might be warranted.
Maybe an extra_scheme_allowed: bool flag on AnyUrl, defaulting to False?

makes sense.

I would like to submit a pr for that. Is that okay?

yes please.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

engstrom picture engstrom  路  3Comments

cdeil picture cdeil  路  3Comments

drpoggi picture drpoggi  路  3Comments

mgresko picture mgresko  路  3Comments

dconathan picture dconathan  路  3Comments