5

I want to use Window functions on sqlite3 on my python3.8 code running on AWS Lambda. They are available since version 3.25.

Unfortunately, on AWS Lambda Python3.8, sqlite3 library is outdated:

>>> sqlite3.sqlite_version
'3.7.17'

while locally, on my homebrew install of Python3.8: (working)

>>> import sqlite3
>>> sqlite3.sqlite_version
'3.31.1'

How can I get an sqlite3 version > 3.25 on AWS Lambda Python 3.8 ?

Vincent J
  • 4,968
  • 4
  • 40
  • 50

1 Answers1

5

I found a way: I used the external package pysqlite3, in the binary version.

in my requirements.txt

pysqlite3-binary==0.4.4

in the code

try:
    import pysqlite3 as sqlite3
except ModuleNotFoundError:
    import sqlite3  # for local testing because pysqlite3-binary couldn't be installed on macos
Vincent J
  • 4,968
  • 4
  • 40
  • 50
  • 1
    Hey Vincent. Please mark your answer as the right one. This is allowed ;) – Jens Dec 14 '20 at 00:49
  • Hi Jens, I didn't know but "You can accept your own answer in 2 days". Also, maybe I don't have the best answer... let's check that tomorrow – Vincent J Dec 14 '20 at 09:09
  • 2
    It works fine in AWS Lambda. I can confirm that current SQLite3 version in Python 3.9 distribution on AWS Lambda is still '3.7.17' so Windows Function fails with an error like: "OperationalError: near '(': syntax error". What I don't get is why current SQLITE3 version (available) is 3.37.0 and the version used in AWS Lambda is 3.7.17 – AngryCoder Feb 21 '22 at 11:27
  • Somehow for me this does not seem to work, django still complains about the old sqlite3 version. Anything that could have gone wrong? – mischa.mole Jul 13 '22 at 09:56
  • Note that `pysqlite3-binary` only has `x86_64` wheels. So it won't install on M1 Macs, etc. I have [solved this problem](https://stackoverflow.com/a/73295545/1749551) using `pipenv`. – Nick K9 Aug 09 '22 at 17:02