NetSuite SDK for Python

3.1.2 · active · verified Mon Apr 13

Netsuite-sdk-py is a Python SDK for accessing NetSuite resources via the NetSuite SOAP web service SuiteTalk. It leverages the `zeep` library internally but abstracts its complexity, providing a simplified interface for interacting with NetSuite APIs. The library is actively maintained with frequent releases, currently at version 3.1.2.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a Token-Based Authentication (TBA) connection to NetSuite using the `netsuitesdk`. It reads credentials from environment variables and then performs a simple query to fetch a list of currencies. NetSuite requires TBA for highly privileged roles.

import os
from netsuitesdk import NetSuiteConnection
from netsuitesdk.exceptions import NetSuiteLoginError

# Ensure these environment variables are set with your NetSuite TBA credentials
NS_ACCOUNT = os.getenv('NS_ACCOUNT', 'YOUR_ACCOUNT_ID')
NS_CONSUMER_KEY = os.getenv('NS_CONSUMER_KEY', 'YOUR_CONSUMER_KEY')
NS_CONSUMER_SECRET = os.getenv('NS_CONSUMER_SECRET', 'YOUR_CONSUMER_SECRET')
NS_TOKEN_KEY = os.getenv('NS_TOKEN_KEY', 'YOUR_TOKEN_KEY')
NS_TOKEN_SECRET = os.getenv('NS_TOKEN_SECRET', 'YOUR_TOKEN_SECRET')

if 'YOUR' in NS_ACCOUNT:
    print("Please set NS_ACCOUNT, NS_CONSUMER_KEY, NS_CONSUMER_SECRET, NS_TOKEN_KEY, NS_TOKEN_SECRET environment variables.")
else:
    try:
        nc = NetSuiteConnection(
            account=NS_ACCOUNT,
            consumer_key=NS_CONSUMER_KEY,
            consumer_secret=NS_CONSUMER_SECRET,
            token_key=NS_TOKEN_KEY,
            token_secret=NS_TOKEN_SECRET
        )
        print(f"Successfully connected to NetSuite account: {nc.account}")

        # Example: Fetch all currencies
        currencies = nc.currencies.get_all()
        print(f"Found {len(currencies)} currencies. First 3: {currencies[:3]}")

    except NetSuiteLoginError as e:
        print(f"NetSuite login failed: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

view raw JSON →