parent module

Functions that provide info on the PWFDF parent item (sometime referred to as the “landing page” for the collection). The parent item hosts individual hazard assessments as a collection of child items.


pwfdf_api.parent.id()

Returns the catalog ID of the PWFDF parent item

id()

Returns the item ID of the PWFDF parent item.

Outputs:

str – The ScienceBase catalog item ID of the PWFDF parent item

pwfdf_api.parent.url(*, fields=None, decode=False, json=False)

Returns the url for the PWFDF parent item

Parent URL
url()
url(*, decode=True)

Returns the URL to the PWFDF parent item. By default, returns a percent-encoded URL suitable for web requests. Set decode=True to return a decoded URL, which is more human-readable.

sbJSON URL
url(*, json=True)
url(*, json=True, fields)

By default, returns a URL for the ScienceBase user interface. Set json=True to return the URL for an sbJSON API query instead. Use the fields input to return a URL used to query specific sbJSON fields.

Inputs:
  • decode (bool) – True to return a decoded URL. False (default) to return a percent-encoded URL suitable for web requests.

  • json (bool) – True to return a URL for a sbJSON API response. False (default) to return a URL for the ScienceBase user interface

  • fields (list[str]) – A list of sbJSON fields that should be queried

Outputs:

str – The url to the PWFDF parent item

pwfdf_api.parent.sbjson(*, fields=None, timeout=15, session=None)

Returns the sbJSON metadata for the PWFDF parent item

Parent sbJSON
sbjson()
sbjson(*, fields)

Queries the PWFDF parent item and returns the sbJSON response as a dict. Use the fields option to only query specific sbJSON fields.

Advanced Web Request
sbjson(..., *, timeout)
sbjson(..., *, session)

Advanced options for implementing the web request. Use timeout to specify a maximum time in seconds for connecting to the ScienceBase server (default is 15 seconds). This option is typically a scalar, but may also use a vector with two elements. In this case, the first value is the timeout to connect with the server, and the second value is the time for the server to return the first byte. You can also set timeout to None, in which case server queries will never time out. This may be useful for some slow connections, but is generally not recommended as your code may hang indefinitely if the server fails to respond.

Use the session option to provide a pre-instantiated requests.Session object for querying the ScienceBase API. If not provided, the command creates (and then closes) a new Session for the request. If you provide a Session object as input, then the session is used to implement the query, but is not closed afterwards. This can be useful when calling pwfdf_api multiple times, as the Session object will preserve the underlying TCP connection, which can improve performance.

Inputs:
  • fields (list[str]) – A list of sbJSON fields that should be queried

  • timeout (float | (float, float) | None) – The maximum number of seconds to connect with the ScienceBase server

  • session (requests.Session) – A pre-existing requests.Session object that should be used to query the ScienceBase API

Outputs:

dict – The sbJSON metadata for the PWFDF parent item

pwfdf_api.parent.browse(*, json=False, fields=None, new=0, autoraise=True)

Opens the PWFDF parent item in a web browser

Open Parent
browse()

Opens the PWFDF parent item in a web browser. Returns a boolean indicating whether the page was successfully opened.

Open sbJSON
browse(*, json=True)
browse(*, json=True, fields)

By default, opens the PWFDF parent item in the ScienceBase user interface. Set json=True to open a sbJSON API response instead. Use the fields option to open a query for specific sbJSON fields.

Browser Options
browse(..., *, new)
browse(..., *, autoraise=False)

Web browser options. The new input controls how the page is opened. 0 opens in the current window, 1 opens a new window, and 2 opens a new tab. Set autoraise=False to disable raising the opened page when possible.

Note

Many web browsers ignore both these options.

Inputs:
  • json (bool) – True to open the page for an sbJSON API response. False (default) to open the PWFDF parent in the ScienceBase user interface

  • fields (list[str]) – A list of sbJSON fields that should be queried

  • new (0 | 1 | 2) – (0 - default) current window, (1) new window, (2) new tab

  • autoraise (bool) – True (default) to autoraise the page. False to not autoraise

Outputs:

bool – True if the page was opened successfully. Otherwise False.