Deliver#

morningstar_data.utils.delivery.deliver(
file_path: str,
config: DeliveryConfig,
wait_for_delivery: bool = False,
delivered_file_name: str | None = None,
) dict#

Delivers a file from a notebook to an email or FTP.

Parameters:
  • file_path (str) – The path to the file that will be delivered, including file name and extension.

  • config (md.utils.DeliveryConfig) –

    An object that holds the delivery configuration information.

    For an email it contains
    • method (DeliveryType): DeliveryType.EMAIL in this case.

    • email_address (str): email_address to send the file to.

    For FTP it contains
    • method (DeliveryType): DeliveryType.FTP in this case.

    • user_name (str): the user_name to login to the ftp server.

    • password (str): the password to login to the ftp server.

    • server (str): the ftp server to use.

    • folder (str): the folder on the ftp server to upload the file to.

    For a Delivery Profile it contains
    • method (DeliveryType): DeliveryType.DELIVERY_PROFILE in this case.

    • delivery_profile_id (str): delivery_profile_id that was setup by MDS. Can be retrieved with get_delivery_profile()

  • wait_for_delivery (bool) – Flag to poll the api to check the delivery status or not. (True=show status)

  • delivered_file_name (Optional[str]) – An optional parameter for the user to specify the file name to be used when delivered. No file extension should be provided. Valid characters are ., -, _, (, ), , a-z, A-Z, 0-9. If the file name includes non-valid characters, an exception will be raised.

Returns:

A dictionary with the ‘job_id’, ‘message’, ‘delivery_status’ keys containing information about the delivery status

Return type:

dict

Examples:

Deliver to an email address.

import morningstar_data as md
import pandas as pd

df = pd.DataFrame({'a':[1], 'b':[2]})
df.to_csv("test_export.csv")

# Email example
delivery_config = md.utils.DeliveryConfig(method=md.utils.DeliveryType.EMAIL, email_address="test@email.com")
md.utils.deliver("test_export.csv", delivery_config)

Deliver to a ftp server.

import morningstar_data as md
import pandas as pd

df = pd.DataFrame({'a':[1], 'b':[2]})
df.to_csv("test_export.csv")

# FTP example
delivery_config = md.utils.DeliveryConfig(method=md.utils.DeliveryType.FTP, user_name="test", password="test", server="ts.ftp.com", folder="data/")
md.utils.deliver("test_export.csv", delivery_config)

Deliver to a Delivery Profile

import morningstar_data as md
import pandas as pd

df = pd.DataFrame({'a':[1], 'b':[2]})
df.to_csv("test_export.csv")

# Delivery Profile example
delivery_config = md.utils.DeliveryConfig(method=md.utils.DeliveryType.DELIVERY_PROFILE, delivery_profile_id="1234")
md.utils.deliver("test_export.csv", delivery_config)

Multiple delivery within a single notebook.

import morningstar_data as md
import pandas as pd

df = pd.DataFrame({'a':[1], 'b':[2]})
df.to_csv("test_export.csv")

ftp_delivery_config = md.utils.DeliveryConfig(method=md.utils.DeliveryType.FTP, user_name="test", password="test", server="ts.ftp.com", folder="data/")
md.utils.deliver("test_export.csv", ftp_delivery_config)

email_delivery_config = md.utils.DeliveryConfig(method=md.utils.DeliveryType.EMAIL, email_address="test@email.com")
md.utils.deliver("test_export.csv", email_delivery_config)

Deliver with a specific filename.

import morningstar_data as md
import pandas as pd

df = pd.DataFrame({'a':[1], 'b':[2]})
df.to_csv("test_export.csv")

# Email example
delivery_config = md.utils.DeliveryConfig(method=md.utils.DeliveryType.EMAIL, email_address="test@email.com")
md.utils.deliver("test_export.csv", delivery_config, delivered_file_name="Delivered_Dataframe_123")
# File delivered will be named "Delivered_Dataframe_123.csv"
Errors:

AccessDeniedError: Raised when the user is not authenticated.

ForbiddenError: Raised when the user does not have permission to access the requested resource.

BadRequestError: Raised when the user does not provide a properly formatted request.

InternalServerError: Raised when the server encounters an unhandled error.

NetworkExceptionError: Raised when the request fails to reach the server due to a network error.

FileNotFoundError: Raised when the file path specified to be delivered does not exist