financialdatapy.request module

This module requests data from web.

financialdatapy.request.get_sec_user_agent() → str[source]

Get the declaring User-Agent required by SEC EDGAR.

SEC rejects requests that do not identify the sender, so each user must declare their own contact instead of sharing one baked into the package.

Raises:

EmptySecUserAgentException – Identity is not provided.

Returns:

User-Agent in SEC’s ‘Name email’ format.

Return type:

str

financialdatapy.request.get_user_agent() → str[source]

Get the User-Agent to send to sources other than SEC.

Some sources reject the outdated browser versions a randomized User-Agent tends to produce, so the user can declare their own browser’s User-Agent instead.

Returns:

User-Agent of the user’s browser, or a randomized one when the user did not declare theirs.

Return type:

str

class financialdatapy.request.Request(url: str, method: str = 'get', headers: dict | None = None, params: dict | None = None, data: dict | None = None)[source]

Bases: object

A class sending and receiving http request.

Parameters:
  • url (str) – Url of the data source.

  • method (str, optional) – Which http methods to request, defaults to ‘get’.

  • headers (dict, optional) – Http request headers, defaults to None.

  • params (dict, optional) – URL parameters to attach, defaults to None.

  • data (Optional[dict], optional) – Data to pass when making POST request, defaults to None.

ResponseType = bytes | str | dict | bs4.BeautifulSoup

Available types of response data.

property headers: dict

Getter method of property headers.

Returns:

Http request headers.

Return type:

dict

property response: Response

Sends a HTTP request to a data source url.

Raises:

requests.exceptions.HTTPError An HTTP error occurred.

Returns:

A response object from the source.

Return type:

requests.Response

response_data(res_type: str) → bytes | str | dict | BeautifulSoup[source]

Return data depending on the data type.

Parameters:

res_type (str) – Type of response data. ‘content’, ‘text’, ‘json’, or ‘beautifulsoup’.

Raises:

NotAvailable – Response data is not available.

Returns:

Bytes, text, or json file containing requested data.

Return type:

ResponseType