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

Pydantic import error : BaseSettings has been moved to the pydantic-settings package. #69

Open
3 of 4 tasks
tcaminel-pro opened this issue Jan 20, 2025 · 1 comment
Open
3 of 4 tasks
Labels
status:needs-triage Has not been triaged yet type:bug Something isn't working

Comments

@tcaminel-pro
Copy link

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

streamlit-pydantic does not work with recent Pydantic versions

When importing the module , we have : Pydantic import error : BaseSettings has been moved to the pydantic-settings package.

Reproducible Code Example

import streamlit as st
import streamlit_pydantic as sp
from pydantic import BaseModel


class ExampleModel(BaseModel):
    some_text: str
    some_number: int
    some_boolean: bool

data = sp.pydantic_form(key="my_sample_form", model=ExampleModel)
if data:
    st.json(data.model_dump())

Steps To Reproduce

Just run basic examples

Expected Behavior

No response

Current Behavior

Traceback (most recent call last):
File "/home/tcl/prj/genai-blueprint/python/test.py", line 2, in
import streamlit_pydantic as sp
File "/home/tcl/.cache/pypoetry/virtualenvs/genai-blueprint-2X6HL8i2-py3.12/lib/python3.12/site-packages/streamlit_pydantic/init.py", line 9, in
from .settings import StreamlitSettings
File "/home/tcl/.cache/pypoetry/virtualenvs/genai-blueprint-2X6HL8i2-py3.12/lib/python3.12/site-packages/streamlit_pydantic/settings.py", line 4, in
from pydantic import BaseSettings
File "/home/tcl/.cache/pypoetry/virtualenvs/genai-blueprint-2X6HL8i2-py3.12/lib/python3.12/site-packages/pydantic/init.py", line 412, in getattr
return _getattr_migration(attr_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tcl/.cache/pypoetry/virtualenvs/genai-blueprint-2X6HL8i2-py3.12/lib/python3.12/site-packages/pydantic/_migration.py", line 296, in wrapper
raise PydanticImportError(
pydantic.errors.PydanticImportError: BaseSettings has been moved to the pydantic-settings package. See https://docs.pydantic.dev/2.10/migration/#basesettings-has-moved-to-pydantic-settings for more details.

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • streamlit-pydantic version: 0.6
  • Python version: 3.12
  • Pydantic version : 2.10

Additional Information

No response

@tcaminel-pro tcaminel-pro added status:needs-triage Has not been triaged yet type:bug Something isn't working labels Jan 20, 2025
@HQuizzagan
Copy link

HQuizzagan commented Feb 14, 2025

@tcaminel-pro I was able to do a workaround (a crude one) in case you need it to work too.

I basically manually revised the streamlit_pydantic source code itself after I did pip install inside my virtual environment. Since I am using venv, these would be in my .venvCustomName/lib/python3.12/site-packages/streamlit_pydantic.

You must first

pip install pydantic-settings

as per the instruction in this update

Now, just look for the settings.py in that directory and simple change the LINE 4

ORIGINAL:

from pydantic import BaseSettings

to NEW:

from pydantic_settings import BaseSettings

Currently, these are the versions that I am using

  • pydantic==2.10.6
  • pydantic_core==2.27.2
  • streamlit-pydantic==0.6.0
  • pydantic-settings==2.7.1

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:needs-triage Has not been triaged yet type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants