Calculate the net profit margin, a profitability ratio that measures the percentage of profit a company earns per dollar of revenue.

The net profit margin ratio is calculated by dividing the net income by the total revenue. It indicates the portion of each dollar of revenue that represents profit after all expenses have been deducted. A higher net profit margin is generally considered favorable.

The formula is as follows:

\[\text{Net Profit Margin Ratio} = \text{Net Income} / \text{Revenue}\]

Also known as: net margin, bottom line margin, net income margin.

No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Net Profit Margin for you. Just ask in plain English.

Calculate the Net Profit Margin in Python

The Net Profit Margin is available in the Ratios module of the open-source Finance Toolkit. Install it with:

pip install financetoolkit -U

Then call get_net_profit_margin as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(["AAPL", "TSLA"], api_key="FINANCIAL_MODELING_PREP_KEY")

net_profit_margin_ratios = toolkit.ratios.get_net_profit_margin()

Which returns:

  2021 2022 2023 2024 2025
AAPL 0.2588 0.2531 0.2531 0.2397 0.2692
TSLA 0.1028 0.1545 0.155 0.073 0.04

Parameters

get_net_profit_margin accepts the following parameters:

  • rounding (int, optional): The number of decimals to round the results to. Defaults to 4.
  • growth (bool, optional): Whether to calculate the growth of the ratios. Defaults to False.
  • lag (int | str, optional): The lag to use for the growth calculation. Defaults to 1.
  • standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.
  • trailing (int): Defines whether to select a trailing period. E.g. when selecting 4 with quarterly data, the TTM is calculated.

The Ratios module page introduces the module, and the sidebar lists all of its functions.

Share