Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating types in python format #795

Open
dhruvmalik007 opened this issue Jul 19, 2024 · 21 comments
Open

Generating types in python format #795

dhruvmalik007 opened this issue Jul 19, 2024 · 21 comments

Comments

@dhruvmalik007
Copy link

Is your feature request related to a problem? Please describe.

I was following the tutorial for generating the database types for supabase here , so I thought normally this command can be adapted for the python in order to generate the corresponding types in python objects

Describe the solution you'd like

to include the command

npx supabase gen types python --project-id "$PROJECT_REF" --schema public > types.py should generate the types in the python.

Describe alternatives you've considered
converting the types generated in ts into py ;) .
Additional context
N.A

@sweatybridge
Copy link
Contributor

Type generation is handled mostly in https://github.com/supabase/postgres-meta/tree/master/src/server/templates where you can see a list of supported type templates.

If you would like to contribute a new language, we will be more than happy to review your PR.

@sweatybridge sweatybridge transferred this issue from supabase/cli Jul 24, 2024
@Mohmn
Copy link

Mohmn commented Jul 25, 2024

Could you please assign this issue to me? I find it very interesting t. Also, could you guide me on anything I need to know to get started? Any specific instructions or resources would be greatly appreciated

@dhruvmalik007
Copy link
Author

dhruvmalik007 commented Jul 26, 2024

thanks @Mohmn for the response . my bad for late response but yeah I understood we will have to define the generator types and the wrapped call functions in order to pythonic format.

but yeah right now I have my plate full in terms of time dedication , so if you want to contribute please feel free to do that.

@TopIvanAbramov
Copy link

Generating types in Python will be really helpfull

@faroukcharkas
Copy link

python types would actually be incredible, having a built in almost-ORM? with supabase would be wild

@urieltfk
Copy link

Please, this would be amazing.

@antopiahk
Copy link

Please, this would be beyond amazing.

@nikita-olechko
Copy link

Wrote a small implementation for Python here:

https://github.com/nikita-olechko/Supabase-Table-Type-Definitions-In-Python/blob/main/README.md

Far from comprehensive, but works.

@ryanpeach
Copy link

ryanpeach commented Oct 1, 2024

Here is my suggestion for the output format #808

I don't think it will be hard to modify the go file to do this for python.

@tresorama
Copy link

tresorama commented Dec 12, 2024

Any updates on this ?

As of today which is the recommended path to convert TS types (generated with supabase cli) into python types ?
Recommended Libraries to use ?

@ryanpeach
Copy link

If it could get testing guidance on my PR I'd continue my work.

@tresorama
Copy link

If it could get testing guidance on my PR I'd continue my work.

You pr would add a new command to supabase cli ?

@ryanpeach
Copy link

No it just adds Python type generation.

@tresorama
Copy link

No it just adds Python type generation.

So it's a standalone script .py ?

@ryanpeach
Copy link

ryanpeach commented Dec 12, 2024

... no. It's been a while but as I remember it the CLI generates types and has a language flag. I'm adding Python as a language.

Probably your confusion is me answering no to your question about adding a new CLI command. It's not a new command, it's the same as always, it's just an option to that command, specifically what language to generate. That option already exists, I'm just adding a new value to its enum, Python.

@ryanpeach
Copy link

To anyone else reading, it's really not that hard to add a language. I ran the existing examples through ChatGPT to get the gist of it, copied the existing code and tests from the most semantically similar language and manually converted the tests to Python. Then I just practiced test driven development to iterate. That's why I need a supabase expert to review my tests and help me cover all the cases.

@ryanpeach
Copy link

Also my pr runs right now for what it's worth, you can use it. It just might produce wrong code, but close enough hopefully at this stage to manually fix. You could provide broken cases back up to the pr to assist.

@tresorama
Copy link

... no. It's been a while but as I remember it the CLI generates types and has a language flag. I'm adding Python as a language.

Probably your confusion is me answering no to your question about adding a new CLI command. It's not a new command, it's the same as always, it's just an option to that command, specifically what language to generate. That option already exists, I'm just adding a new value to its enum, Python.

You got it! That "no" made me fantasticate ...
Now it's extremely clear. Thanks for it

@isaacmond
Copy link

It'd be great to see this added!

@rdewolff
Copy link

rdewolff commented Jan 7, 2025

Would love to have this too! 🚀

@pmespresso
Copy link

pmespresso commented Jan 10, 2025

It's not perfect but I made this web tool to convert database.types.ts to Pydantic models.

https://r49hewfznfqdenhg.vercel.app/

Screenshot 2025-01-10 at 1 51 35 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests