Tag: Python
-
How to get rid of SQLAlchemy deprecated API while TDD with pytest
Deprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. To prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to “sqlalchemy<2.0”. Set environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings. Set environment variable export SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
-
How to stream media file from s3 directly to AWS lambda FFMPEG Python example
There is no need to download a file and put it inside your lambda’s /tmp folder to process it with FFMPEG. I will show you how to do it “on the fly”. Just stream a damn file directly into ffmpeg! def execute_ffmpeg_command(input_file: str): “”” Execute the given ffmpeg command against the input file. Args: input_file…
-
How to measure execution time of a function in Python, with example
this would be the timeit decorator: from functools import wraps import time def timeit(func): @wraps(func) def timeit_wrapper(*args, **kwargs): start_time = time.perf_counter() result = func(*args, **kwargs) end_time = time.perf_counter() total_time = end_time – start_time print(f’Function {func.__name__}{args} {kwargs} Took {total_time:.4f} seconds’) return result return timeit_wrapper example how this decorator works: @timeit def lol(): print(“lmao, Serhii is the…
-
AWS: botocore.exceptions.NoRegionError: You must specify a region.
solution: export AWS_DEFAULT_REGION=us-west-2
-
How to assert 2 simple functions return the same value in Python?
To test that two functions return the same value, you can use the assert statement in Python. Here’s an example of how to do it: def function1(): return 5 def function2(): return 5 assert function1() == function2() In this example, we have two functions function1 and function2 that both return the integer value 5. We…
-
Python dict.get() vs dict[‘brackets’], which approach is better?
Using the .get() method on a dictionary is generally considered a better approach than using the direct dictionary indexing dictionary[‘key’] method because the .get() method provides a default value if the key is not found in the dictionary, whereas direct dictionary indexing raises a KeyError exception. Here is an example: my_dict = {‘a’: 1, ‘b’:…
-
Django tips and tricks
When to use gettext() and gettext_lazy() Functions for TranslationAll of these snippets, Django tips and tricks have been tested on real-world Django applications by me. I’m using each of them in my SaaS projects. I wrote this article in a specific manner, less text – more code – more solutions! If you have any issue/error…
-
Python Programming Language 3.7 Cheat Sheet Image
Python Programming Language 3.7 Cheat Sheet Image for beginners and people who want to find out what’s new on Python 3.7