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()}")