p2api
The ESO Phase 2 Application Programming Interface (API) uses the lightweight JSON standard as data format to exchange information between your application and the Phase 2 server at ESO. In order to program more conveniently against the API, it is helpful to create small, language-specific bindings to the API. We provide a simple example binding for Python, i.e. p2api.
As of version 1.2.3: Support for triggering RRMs and getting their status as well as that of the system.
As of version 1.2.3: Support for triggering RRMs is posibly actually functional!
As of version 1.1.0: Added support for triggering RRMs and ToOs.
As of version 1.0.10: Removed script p2api_add_absolute_time_intervals.
As of version 1.0.7: Improved backward compatibility for older systems.
As of version 1.0.6: Added script p2api_add_absolute_time_intervals.
As of version 1.0.3: support for <url>,<access_token> constructor.
As of version 0.97.2: support for La Silla.
Please see the ESO-USD p2api page for more details.
Phase 2 programmatic API documentation can be found here.
Create a dedicated Virtual Environment for p2api
bash
python -m venv "${HOME}/envs/p2api"
. "${HOME}/envs/p2api/bin/activate"
python -m pip install --upgrade pip
python -m pip install p2api
RRM observations
Major change to authentication for RRM Triggers
Prior to this REST-API, trigger authentication was via the pre-authorized trigger-code, i.e. the unique combination of "account-code", instrument name and OB name.
With the REST-API, trigger authentication is based on p2-credentials authentication. This means that a given OB can be triggered if the authenticated P2 user has permission to "see"/edit the OB (i.e. the PI of the run and all phase-2-delegates). In addition the run must be of RRM-type, and the OB must be in status '+' (for testing 'D'="Certified" is also allowed.)
Prepare the environment
First activate the environment ( if it is not already activated):
bash
. "${HOME}/envs/p2api/bin/activate"
Next save your ESO User Portal credentials in the keyring if you want to be able to trigger without being prompted for the password each time:
up_username=<ESO_User_Portal_username>
p2api_rrm_trigger -u ${up_username} -S
Testing
Check the status of the RRM system:
up_username=<ESO_User_Portal_username>
p2api_rrm_system_status -u ${up_username} \
--env=production \
--obId=1234567
If the system is ONLINE, then you are ready to make a test trigger:
up_username=<ESO_User_Portal_username>
p2api_rrm_trigger -u ${up_username} \
--env=production \
--obId=1234567 \
--RA=10:20:30.000 --DEC=-35:01:30.600 \
--finding_charts /<absolute>/<file>/<path>/<fc_filename_1.jpg>,<relative>/<file>/<path>/<fc_filename_2.jpg>
This command will submit the trigger and then monitor execution progress, creation of ticket and upload of Finding Charts. In testing mode it will create (if needed) a ticket for your run that will be used for all trigger tests (rather an a new ticket for each trigger-test.)
Real triggers
To check the system status of the LIVE RRM system and/or to make an actual trigger, not just a test trigger & ticket, add the command line argument --NOT_A_TEST to each of the above commands. For real (non-test) triggers a new ticket will be create for each trigger.
Check the status of the RRM system:
up_username=<ESO_User_Portal_username>
p2api_rrm_system_status -u ${up_username} \
--env=production \
--obId=1234567 \
--NOT_A_TEST
If the system is ONLINE, then you are ready to make a test trigger:
up_username=<ESO_User_Portal_username>
p2api_rrm_trigger -u ${up_username} \
--env=production \
--obId=1234567 \
--RA=10:20:30.000 --DEC=-35:01:30.600 \
--finding_charts /<absolute>/<file>/<path>/<fc_filename_1.jpg>,<relative>/<file>/<path>/<fc_filename_2.jpg> \
--NOT_A_TEST
This command will submit the trigger and then monitor execution progress, creation of ticket and upload of Finding Charts. In testing mode it will create (if needed) a ticket for your run that will be used for all trigger tests (rather an a new ticket for each trigger-test.)
Integration into your own python tool(s)
The following is currently un-tested, their maybe bugs, please contact ESO-USD via ticket if you need help...
To integrate the utilities into your own python tool(s) the following gives one way to do that. Feel free to inspect the p2api code to figure out the best way to do it yourself.
In all of the following RRM methods, the object options is assumed to exist (e.g. as returned by a get_options class based on Python built-in class argparse.ArgumentParser, not all attributes have to be specified as command line options, they can be addded to the options object by the code). It must have the following attributes:
env:str # ehe name of the environment, by default 'production'
user:str # the user portal username
pw:str # the password of the user portal user
obId:int # the OB Id number
testing:bool # True|False for testing
quiet:bool # True|False for quiet logging|actions
debug:bool # True|False for debug logging|actions
The additional attributes are required for the rrm_trigger_oneOB method:
RA:str # hh:mm:ss.sss
DEC:str # ±dd:mm:ss.sss
phone:str # Contact phone number for triggerer (or delegate)
notify:str # comma separated list of email addresses to include in trigger ticket CCs
calibrations:bool # True|False for Additional calibrations required. Please specify details in comments.
comments:str # Comments for trigger
The additional attributes are optional for the rrm_trigger_oneOB method:
finding_charts:str # comma separated list of finding chart filenames (relative or absolute paths)
Get the system status and then trigger an RRM OB execution is fthe system is ONLINE.
overall_sdt=datetime.datetime.now(tz=datetime.timezone.utc)
import logging
import datetime
import p2api
from p2api.utils.rrm_system_status import oneOB as rrm_system_status_oneOB
from p2api.utils.rrm_trigger import oneOB as rrm_trigger_oneOB
logger=logging.getLogger()
api=p2api.ApiConnection(environment=options.env, username=options.user, password=options.pw)
# system status
r=rrm_system_status_oneOB(
api=api,
options=options,
obId=options.obId,
overall_sdt=overall_sdt,
)
if r is not None :
if r.status_code in [200,201,202,204] :
rj=r.json()
rrm_syestem_status=rj['system_state']['system_state']
else :
logger.error("Query returned unexpected response status_code")
else :
logger.error("Query returned unexpected response")
if rrm_system_status == 4 :
# Make trigger
trigger_ticket_status=rrm_trigger_oneOB(
api=api,
options=options,
obId=options.obId,
overall_sdt=overall_sdt,
)
Metadata
Release files for p2api 1.2.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| p2api-1.2.9.tar.gz | 39.3 kB | Without provenance | Details for p2api-1.2.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| p2api-1.2.9-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for p2api-1.2.9-py2.py3-none-any.whl |
Total release size: 92.8 kB
Release files / p2api-1.2.9.tar.gz
| Download URL | p2api-1.2.9.tar.gz |
|---|---|
| Size | 39.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1731c33745b7e1f168b350463a6e86a4a8f625fd442a5723dd9d2f5e59eb1afd
|
|
BLAKE2b-256 checksum How to use checksums |
14d9e31e973ec02ecf8d4be7c33041afc0cd983f700437a14edf230f3a099f38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Release files / p2api-1.2.9-py2.py3-none-any.whl
| Download URL | p2api-1.2.9-py2.py3-none-any.whl |
|---|---|
| Size | 53.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
d16bb2d9bf831c08b9348e9267dcc1a645f13b45c64c2575cc0096328f6e03c0
|
|
BLAKE2b-256 checksum How to use checksums |
b71749189f34e8f4badeb216c03f5b7f9017551050814679c8028f3e8f90d134
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Security for p2api 1.2.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.