Session(api_key: Optional[str] = None, key_location: Optional[str] = None)¶
Class to hold information on the Astrometry.net API session. Is able to read an API key from multiple possible locations, and login to retrieve a session key (stored in the id attribute).
The API key used to log in.
Normal usage of a session is as follows; you create the Session class, and then
>>> session = Session('the api key') >>> session.login()
There are multiple ways of giving your api key. You can just give it as a plain string (not very safe):
>>> session_1 = Session(api_key='the api key')
You can enter it in a separate private file and give the path to it. This file should only contain the key, nothing else.
>>> session_2 = Session(key_location='path/to/file/with/key')
You can specify the key as an environment variable named
>>> session_3 = Session()
If you do not specify any of the above, an exception will be thrown:
>>> Session() APIKeyError
APIKeyError – When no API key is specified (see examples)
login(force: bool = False) → None¶
Method used to log-in or start a session with the Astrometry.net API.
Only sends a request if it is absolutely needed (or forced to). If
logged_inis True, it assumes the session is still valid (there is no way to check if the session is still valid).
SessionRequest(session: astrometry_net_client.session.Session, *args, **kwargs)¶
Wraps the normal Request around an authentication layout, ensuring the user is logged in and the session key is send alongside the request.
The separate login request (if needed) is only send just before the original request is made, (e.g. when calling make / _make_request).