Large increase in memory usage in new Python SDK

Hi,

I recently updated my application to use the new 42.x+ Python SDK, and have noticed it caused a huge increase in memory consumption - 109MB - which actually doubles the memory usage of each python gunicorn worker.

This occurs when from square import Square is called, before the library is even used.

This application is used across multiple servers and deploying the new SDK would double my monthly hosting costs. This looks like a bug in the way the library is written? Loading the import of the client also takes 16 seconds!

See below for profiling of a test function with memory-profiler. I ran this against SDK version 43.0.0.20250618 but this is true of all versions of the new SDK:

Python 3.13.5 (main, Jun 12 2025, 22:45:02) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from square_api.handlers import test_import_square_memory
>>> test_import_square_memory()
Starting: 2025-06-26 10:45:56.476450
Imported Square Legacy: 2025-06-26 10:45:56.655781
Imported new Square SDK: 2025-06-26 10:46:12.907839
Filename: /home/web/app/square_api/handlers.py

Line #    Mem usage    Increment  Occurrences   Line Contents
=============================================================
    20    106.3 MiB    106.3 MiB           1   @profile
    21                                         def test_import_square_memory():
    22    106.3 MiB      0.0 MiB           1       print(f"Starting: {dt.datetime.now()}")
    23    107.4 MiB      1.1 MiB           1       from square_legacy.client import Client as LegacySquare
    24    107.4 MiB      0.0 MiB           1       print(f"Imported Square Legacy: {dt.datetime.now()}")
    25    216.5 MiB    109.1 MiB           1       from square import Square
    26    216.5 MiB      0.0 MiB           1       print(f"Imported new Square SDK: {dt.datetime.now()}")

:waving_hand: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Python SDK Migration Guide
Square Python SDK Quickstart
Common Square API Patterns

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

Any thoughts on this from the developers? This makes the new SDK unusable for me. Thanks.

When your doing this are you importing other modules as well? :slight_smile: