Skip to main content

API access for the Southern African Large elescope (SALT).

Project description

pyastrosalt

PyAstroSALT is a wrapper around the RESTful API for observations with the South African Astronomical Observatory (SALT).

It can be used for

  • validating proposals
  • submitting proposals
  • making any API request

Installation

PyAstroSALT can be installed from PyPI:

pip install pyastrosalt

Validating a proposal

SALT proposals are stored as zip files. If you want to see what such a zip file looks like, you can create a proposal in the Principal Investigator Proposal Tool (PIPT) and export it using the menu item File | Export as Zip File.

The following assumes that you have a proposal proposal.zip in the working directory and that the proposal code is 2026-1-SCI-042.

You start by creating a session and authenticating with your SALT user credentials. For testing, you can use the playground instead of the production server:

from getpass import getpass
from pyastrosalt.session import Session

username = input("Your SALT username: ")
password = getpass("Your SALT password: ")
session = Session()
session.use_playground()
session.login(username=username, password=password)

You can now validate the proposal:

from pyastrosalt.submission import validate

valid, errors = validate(session, "proposal.zip", "2026-1-SCI-042")
if valid:
    print("The proposal is valid.")
else:
    print("Validation failed with the following error(s):")
    for error in errors:
        print(f"- {error}")

Submitting a proposal

As in the previous section, the following example assumes that you have a proposal proposal.zip in the working directory and that the proposal code is 2026-1-SCI-042.

If you want to submit the proposal, you start by creating a session and authenticating. For testing, you can use the playground instead of the production server:

from getpass import getpass
from time import sleep

from pyastrosalt.session import Session

username = input("Your SALT username: ")
password = getpass("Your SALT password: ")
session = Session()
session.use_playground()
session.login(username=username, password=password)

You can now call the submit function. This function returns a Submission instance, which yiu can poll for the submission status, proposal code and (if applicable) submission error:

from time import sleep
from pyastrosalt.submission import submit, SubmissionStatus

submission = submit(
    session, "proposal.zip", "2026-1-SCI-042"
)
while submission.status == SubmissionStatus.IN_PROGRESS:
    print("Waiting for submission to finish...")
    sleep(10)
    
if submission.status == SubmissionStatus.SUCCESS:
    print(f"Success! The proposal code is {submission.proposal_code}.")
else:
    print(f"The validation failed with the following error:\n{submission.error}")

Using the SALT API

To make a request to the SALT API, you can create a session, authenticate and issue an HTTP request. Refer to the Requests documentation for details on the available request methods (get, post, put, patch, delete and request).

The following example shows how you can get details about your SALT propoals:

from getpass import getpass

from pyastrosalt.session import Session

# Get a session and authenticate
username = input("Your SALT username: ")
password = getpass("Your SALT password: ")
session = Session()
session.use_playground()
session.login(username=username, password=password)

# Make the API request
response = session.get("/proposals/")
if not response.ok:
    raise Exception("The API request failed.")

# Use the response from the API
proposals = response.json()
for proposal in proposals:
    print(f"{proposal['proposal_code']}: {proposal['title']}")

You can find the available API endpoints on the SALT API documentation page.

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

pyastrosalt-0.2.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

pyastrosalt-0.2.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file pyastrosalt-0.2.0.tar.gz.

File metadata

  • Download URL: pyastrosalt-0.2.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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 pyastrosalt-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4e6d14eefaa34520fca1ac6f53675053c42deb5526d4d8605a940ea1dca316e4
MD5 7a5c8d54a70ecef1581c590133bb1def
BLAKE2b-256 a3082a45dac29e5e7d2084425209ebf55c6cc2ef75d54c1b3dd65cb54bb9d09f

See more details on using hashes here.

File details

Details for the file pyastrosalt-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyastrosalt-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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 pyastrosalt-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe94f6290c7e2d007256b7e7b615ad7b6c041f347dcf5df8385e572e7c10dd79
MD5 45279d1be119fde256dbf6c87b001546
BLAKE2b-256 6d740ba659828893ce394ba999f64dabbd0f051039d7ab474363394d54c97b45

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