This project presents a simple CRUD (Create, Read, Update, Delete) application built with Python and Streamlit, designed for managing user information. It leverages a PostgreSQL database for data persistence and Docker for easy deployment.
- Python 3.10+: The core programming language.
- Streamlit: For building interactive web applications with Python.
- SQLAlchemy: An SQL toolkit and Object-Relational Mapper (ORM) for Python.
- Alembic: A database migration tool for SQLAlchemy.
- Pydantic: Data validation and settings management using Python type hints.
- PostgreSQL: A powerful, open-source relational database.
- Poetry: A dependency management and packaging tool for Python.
- Docker & Docker Compose: For containerization and orchestrating multi-container Docker applications.
You can run this project using Docker Compose or by setting it up locally.
- Clone the repository:
git clone https://github.com/your-repo/python-crud-streamlit.git cd python-crud-streamlit - Configure Environment Variables:
The
docker-compose.ymlfile contains environment variables for the PostgreSQL database (e.g.,POSTGRES_USER,POSTGRES_PASSWORD,POSTGRES_DB) and the application'sDATABASE_URL. You can modify these directly in thedocker-compose.ymlfile to suit your needs. Important: If you change the database connection string indocker-compose.yml, you must also update thesqlalchemy.urlinalembic.inito match your new database configuration. This ensures Alembic can connect to the correct database for migrations. - Build and Run:
This command will build the Docker images, start the PostgreSQL database, and launch the Streamlit application.
docker-compose up --build -d
- Access the Application:
Once the containers are up and running, open your web browser and navigate to
http://localhost:8501.
- Clone the repository:
git clone https://github.com/your-repo/python-crud-streamlit.git cd python-crud-streamlit - Install Poetry (if you don't have it):
pip install poetry
- Install Dependencies:
poetry install
- Set up PostgreSQL: Ensure you have a PostgreSQL database running and accessible. Create a database for the application.
- Configure Environment Variables:
Create a
.envfile in the project root or set environment variables directly for your database connection. For example:Important: Ensure theDATABASE_URL="postgresql://user:password@localhost:5432/your_database_name"sqlalchemy.urlinalembic.inimatches your local database connection string. - Run Database Migrations:
poetry run alembic upgrade head
- Run the Streamlit Application:
poetry run streamlit run src/main.py
- Access the Application:
Open your web browser and navigate to the address provided by Streamlit (usually
http://localhost:8501).
Este projeto apresenta uma aplicação CRUD (Criar, Ler, Atualizar, Excluir) simples, desenvolvida com Python e Streamlit, projetada para gerenciar informações de usuários. Ele utiliza um banco de dados PostgreSQL para persistência de dados e Docker para facilitar a implantação.
- Python 3.10+: A linguagem de programação principal.
- Streamlit: Para construir aplicações web interativas com Python.
- SQLAlchemy: Um kit de ferramentas SQL e Mapeador Objeto-Relacional (ORM) para Python.
- Alembic: Uma ferramenta de migração de banco de dados para SQLAlchemy.
- Pydantic: Validação de dados e gerenciamento de configurações usando type hints do Python.
- PostgreSQL: Um banco de dados relacional poderoso e de código aberto.
- Poetry: Uma ferramenta de gerenciamento de dependências e empacotamento para Python.
- Docker & Docker Compose: Para conteinerização e orquestração de aplicações Docker multi-container.
Você pode executar este projeto usando Docker Compose ou configurando-o localmente.
- Clone o repositório:
git clone https://github.com/your-repo/python-crud-streamlit.git cd python-crud-streamlit - Configurar Variáveis de Ambiente:
O arquivo
docker-compose.ymlcontém variáveis de ambiente para o banco de dados PostgreSQL (por exemplo,POSTGRES_USER,POSTGRES_PASSWORD,POSTGRES_DB) e aDATABASE_URLda aplicação. Você pode modificá-las diretamente no arquivodocker-compose.ymlpara atender às suas necessidades. Importante: Se você alterar a string de conexão do banco de dados emdocker-compose.yml, você também deve atualizar osqlalchemy.urlemalembic.inipara corresponder à sua nova configuração de banco de dados. Isso garante que o Alembic possa se conectar ao banco de dados correto para as migrações. - Construir e Executar:
Este comando irá construir as imagens Docker, iniciar o banco de dados PostgreSQL e lançar a aplicação Streamlit.
docker-compose up --build -d
- Acessar a Aplicação:
Assim que os contêineres estiverem em execução, abra seu navegador e navegue para
http://localhost:8501.
- Clone o repositório:
git clone https://github.com/your-repo/python-crud-streamlit.git cd python-crud-streamlit - Instalar Poetry (se você não tiver):
pip install poetry
- Instalar Dependências:
poetry install
- Configurar PostgreSQL: Certifique-se de ter um banco de dados PostgreSQL em execução e acessível. Crie um banco de dados para a aplicação.
- Configurar Variáveis de Ambiente:
Crie um arquivo
.envna raiz do projeto ou defina as variáveis de ambiente diretamente para a conexão do seu banco de dados. Por exemplo:Importante: Certifique-se de que oDATABASE_URL="postgresql://user:password@localhost:5432/nome_do_seu_banco_de_dados"sqlalchemy.urlemalembic.inicorresponda à sua string de conexão do banco de dados local. - Executar Migrações do Banco de Dados:
poetry run alembic upgrade head
- Executar a Aplicação Streamlit:
poetry run streamlit run src/main.py
- Acessar a Aplicação:
Abra seu navegador e navegue para o endereço fornecido pelo Streamlit (default
http://localhost:8501).



