A Python-based fullstack project that allows users to search and display images from the NASA Image and Video Library using:
- 🎨 NiceGUI for the frontend UI
- ⚡ Astral UV for ultra-fast dependency and tool management
- ✅ Pre-commit for consistent code formatting and linting
- 🪂 [Fly.io] (https://nasa-api-code-challenge.fly.dev/)
git clone https://github.com/CodeConnoisseur74/NASA-API-Code-Challenge.git
cd NASA-API-Code-Challenge
curl -Ls https://astral.sh/uv/install.sh | sh
Make sure it's working:
uv --version
Install dependencies and dev tools:
uv add "fastapi[standard]" nicegui httpx
uv add --dev pre-commit
Set up pre-commit with:
uv run pre-commit install
.
├── app/
│ ├── __init__.py
│ ├── main.py # FastAPI app with /search endpoint
│ └── nasa_api.py # NASA API query logic
├── ui/
│ └── main.py # NiceGUI frontend
├── .pre-commit-config.yaml
├── pyproject.toml
└── README.md
uv run fastapi dev app/main.py
The API will be available at: http://localhost:8000/search?query=moon&media_type=
uv run python ui/main.py
The frontend will open at: http://localhost:8080
Search for terms like "nebula", "apollo", or "galaxy" to view NASA s!
To enforce code quality and formatting, this project uses:
-
ruff for linting and formatting
-
Pre-commit hooks for whitespace, file endings, and YAML checks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.12
hooks:
- id: ruff
args: [ --fix, --extend-select=I]
- id: ruff-format
Run manually with:
uv run pre-commit run --all-files
curl -L https://fly.io/install.sh | sh
- Authenticate
fly auth login
fly launch
- Choose a unique app name (e.g., nasa-api-code-challenge)
- When prompted, select your preferred region (e.g., fra for Frankfurt)
- This creates a fly.toml config file
FROM python:3.12-slim
# Set working directory
WORKDIR /app
# Copy requirements.txt first (this helps with Docker caching)
COPY requirements.txt .
# Install system dependencies (optional but recommended for httpx and other packages)
RUN apt-get update && apt-get install -y \
build-essential \
libffi-dev \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the app
COPY . .
# Expose port 8080 for Fly.io
EXPOSE 8080
# Run the NiceGUI app
CMD ["python", "main.py"]
In main.py, ensure:
ui.run(
host='0.0.0.0',
port=int(os.environ.get('PORT', 8080)),
title='NASA Explorer',
dark=True,
reload='FLY_ALLOC_ID' not in os.environ,
)
git init
git add .
git commit -m "Prepare for GitHub deployment
git remote add origin https://github.com/yourusername/nasa-gallery.git
git push -u origin main
fly deploy
- No docker-compose.yml is required for deployment
- Make sure all Python dependencies are listed in requirements.txt
- Use .dockerignore to exclude unnecessary files (e.g., .venv, .git)
- Add metadata (favicon, SEO title, meta tags)
- Add testing
This project uses the NASA Image and Video Library, which is public and does not require an API key.
NASA Image and Video API Reference Documentation: https://images.nasa.gov/docs/images.nasa.gov_api_docs.pdf
This challenge is part of the Pybites Circle Community. This is a community dedicated to growing your skills and network as a Python Developer so you can achieve your career and Python goals.