Skip to content

procoder3001/python_env_template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Project Setup Guide

This guide covers setting up a Python development environment using pyenv, poetry, and HashiCorp Vault for secrets management.

Prerequisites

Install pyenv on macOS

# Install pyenv using Homebrew
brew install pyenv

# Add pyenv to your shell (add these to your ~/.zshrc)
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc

# Reload your shell
source ~/.zshrc

Install Poetry

curl -sSL https://install.python-poetry.org | python3 -

Install HashiCorp Vault

brew tap hashicorp/tap
brew install hashicorp/tap/hcp

# Login and initialize
hcp auth login
hcp profile init --vault-secrets

Project Setup

why we use poetry and pyenv:

  • pyenv ensures your project uses the exact Python version you want, even if it’s not the system default.
  • Poetry by itself doesn’t install or manage Python versions — it just uses what’s available.
  1. Create and activate a new Python environment:
# Install Python version
pyenv install 3.12.2

# Create virtual environment
pyenv virtualenv 3.12.2 project-env-3.12.2

# Activate environment
pyenv activate project-env-3.12.2
  1. Initialize Poetry project:
# Initialize new project
poetry init

# Verify environment
poetry env info
poetry run python --version
  1. Add dependencies:
# Add main dependencies
poetry add fastapi uvicorn

# Add development dependencies
poetry add -G dev pytest black isort mypy

HashiCorp Vault Integration

# Open secrets
hcp vault-secrets secrets open {desired secret}

# Run application with injected secrets
hcp vault-secrets run -- python3 my_app.py

Cursor IDE Configuration

Create the following files in your project root:

  1. .cursorignore:
# Ignore virtual environments
.venv/
venv/
__pycache__/
*.pyc

# Ignore build artifacts
dist/
build/
*.egg-info/

# Ignore environment files
.env
.env.*
  1. .cursorrules:
{
  "python": {
    "formatter": "black",
    "linter": "flake8",
    "typeChecker": "mypy"
  }
}
  1. .vscode/settings.json (for Cursor compatibility):
{
  "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
  "python.analysis.typeCheckingMode": "basic",
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.organizeImports": true
  }
}

Project Structure

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published