I using Python 3.13.5 and have used pip install snaptrade-python-sdk==13.0.39
My error is “SnapTrade is not defined” so I cannot even initialize the snaptrade client
My code:
import os
from SnapTrade import snaptrade_client
# 1) Initialize a client with your clientID and consumerKey.
snaptrade = SnapTrade(
consumer_key=os.environ\["xxxxxxxxxx"\],
client_id=os.environ\["xxxxxxxx"\],
)
Exception has occurred: ModuleNotFoundError
No module named ‘SnapTrade’
File “C:\____PYTHON\SnapTrade\InitializeClient.py”, line 3, in
from SnapTrade import snaptrade_client
ModuleNotFoundError: No module named ‘SnapTrade’
The import is reversed. The installed SDK provides the snaptrade_client module, which contains the SnapTrade class:
import os
from snaptrade_client import SnapTrade
snaptrade = SnapTrade(
consumer_key=os.environ["SNAPTRADE_CONSUMER_KEY"],
client_id=os.environ["SNAPTRADE_CLIENT_ID"],
)
The strings inside os.environ[...] must be environment variable names, not the actual key values.
If from snaptrade_client import SnapTrade still fails, check that pip installed the package for the same Python interpreter that runs the script:
python -m pip show snaptrade-python-sdk
python -c "from snaptrade_client import SnapTrade; print('import ok')"
Also make sure the project does not have a local file or folder named snaptrade_client, which could shadow the installed package.
Camila, Thank you for your response. I have been running this from VSCode (is this the problem?)
I have no file or directory named snaptrade_client.
after running python -c “from snaptrade_client import SnapTrade; print(‘import ok’)”
I get
Requires: aiohttp, certifi, cryptography, frozendict, python-dateutil, typing_extensions, urlib3
Additionally, I understand for security reasons it’s best to use an .env file for my consumer key and client ID. But using actual key values should work, correct? Perhaps I should use a virtual environment and get VSCode to use that? Once I get a connection I’ll make quick progress. Thanks again.