Skip to content

CodeConnoisseur74/NASA-API-Code-Challenge

Repository files navigation

🌌 NASA Explorer (🚀 Pybites Community Python Challenge)

Live Site:

NASA Explorer

A Python-based fullstack project that allows users to search and display images from the NASA Image and Video Library using:


📦 Setup Instructions

1. Clone the Repository

git clone https://github.com/CodeConnoisseur74/NASA-API-Code-Challenge.git
cd NASA-API-Code-Challenge

2. Install Astral UV (if not installed)

curl -Ls https://astral.sh/uv/install.sh | sh

Make sure it's working:

uv --version

3. Initialize the Project (Dependencies & Tools)

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

4. Project Structure

.
├── 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

🚀 Running the App

✅ 1. Run FastAPI Backend

uv run fastapi dev app/main.py

The API will be available at: http://localhost:8000/search?query=moon&media_type=

✅ 2. Run NiceGUI Frontend

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!

✅ Pre-commit Setup (Optional but Recommended)

To enforce code quality and formatting, this project uses:

  • ruff for linting and formatting

  • Pre-commit hooks for whitespace, file endings, and YAML checks

🔧 .pre-commit-config.yaml

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

🚀 Deployment to Fly.io

📦 Prerequisites

curl -L https://fly.io/install.sh | sh
  • Authenticate
fly auth login

🛠️ Step-by-Step Deployment

📦 2.Initialize your Fly.io app

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

🚀 3. Configure Docker

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"]

4. Make sure your app listens on the correct address and port

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,
)

5. Deploy to gitHub

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

6. Deploy the app

fly deploy

✅ Note:

  • 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)

Left to Implement

  • Add metadata (favicon, SEO title, meta tags)
  • Add testing

🌐 About the NASA API Used

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

🌐 About Pybites Community Python

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.

About

Pybites Code Challenge. Query NASA images and videos using NASA's open source APIs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published