Skip to main content

Simple NASA API Client

Project description

Prepare environment

mkdir nasa-client
cd nasa-client
uv init --package nasa-client --python=3.14
uv venv
source .venv/bin/activate
touch main.py  

Create .env file

touch .env .gitignore

# Add your NASA_API_KEY API key to the .env file
echo "NASA_API_KEY=your_api_key_here" >> .env
cd src/nasa_client
touch client.py

Add packages

uv add requests python-dotenv loguru black

from .client import NASAClient

  • makes it easy to import
  • . means from the current package
  • go inside client.py and import NASAClient
  • without it, users would have to write
    • from nasa_client.client import NASAClient
  • with it, users can simply write
    • from nasa_client import NASAClient

__all__=[NASAClient]

  • this controls what gets exported publicly from your package
  • think of it like a public API whitelist
  • if someone does from nasa_client import * (cleaner, more user-friendly API)
    • only things listed in __all__ will be imported

Bonus: what happens without __all__?

Format code

black main.py
black src/nasa_client/*.py

Git

git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/<USERNAME>/nasa-client.git
git push -u origin main

Run Locally

uv run main.py 

Build Package

uv add build twine

Build and Publish to PyPI

# build project
uv build

# publish project
export UV_PUBLISH_USERNAME="__token__"
export UV_PUBLISH_PASSWORD="pypi-AgEIcHlwaS5vcmcCJ..."
uv publish

# another
uv publish --username __token__ --password pypi-AgEIcHlwaS5vcmcCJ...

# another
export PYPI_TOKEN="pypi-AgEIcHlwaS5vcmcCJ..."
uv publish --username __token__ --password $PYPI_TOKEN --repository-url https://test.pypi.org/legacy/

# publish to testpypi
uv publish --username __token__ --password pypi-AgEIcHlwaS5vcmcCJ...

# using twine
export TWINE_USERNAME=__token__
export TWINE_PASSWORD=pypi-AgENdGVzdC5
twine upload --repository testpypi dist/*

twine upload dist/* \
--verbose \
--repository testpypi \
--username __token__ \
--password pypi-AgEIcHlwaS5vcmcCJ...


# debug trick
uv publish https://test.pypi.org/legacy/ \
  --username __token__ \
  --password $PYPI_TOKEN

Install Wheel Files

pip install dist/nasa-client-0.1.0-py3-none-any.whl
uv tool install dist/nasa-client-0.1.0-py3-none-any.whl

USAGE

  • pip install nasa-client
  • export NASA_API_KEY=tYYvy2MZehnbOAY5t...
import os
from nasa_client import NASAClient

NASA_API_KEY=os.getenv("NASA_API_KEY")

nasa = NASAClient(api_key="YOUR_API_KEY")

if __name__ == "__main__":
    # get astronomy picture of the day
    photo = nasa.get_apod()
    print(photo["title"])
    
    # search asteroids
    asteroids = nasa.search_asteroids("2026-04-01", "2026-04-06")
    print(asteroids["element_count"])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nasa_client_pro-0.1.0.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nasa_client_pro-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file nasa_client_pro-0.1.0.tar.gz.

File metadata

  • Download URL: nasa_client_pro-0.1.0.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nasa_client_pro-0.1.0.tar.gz
Algorithm Hash digest
SHA256 69600c21cb378e2121d8a3f523ae262d8edbfc9af2cb8a31dee87c594e16e4a9
MD5 e5144405e9c6c3c5265b3caff93a8e39
BLAKE2b-256 5d7e3aa7fbc1d25be8254eb141f3b1fc736e0b91fe6b1298b830a83be7b1016f

See more details on using hashes here.

File details

Details for the file nasa_client_pro-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nasa_client_pro-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nasa_client_pro-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d205c367a4a543c51518d4248131183f27fe1bd9aa930e9ebc652c00c11ad4c9
MD5 fda29e3d080956abb7c7b7e8a97c829a
BLAKE2b-256 f6d996ac050a8a2d705b9370dd9bcd47b9eb9e9eeee1cc74e4e7b734e366622a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page