Tag: Python

  • How to get rid of SQLAlchemy deprecated API while TDD with pytest

    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

    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

    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…

  • Released @responseWithBarcodeBot (Generate Bar Code Telegram bot)

    Released @responseWithBarcodeBot (Generate Bar Code Telegram bot)

    Generate Bar Code Telegram Bot I’m alive! Please visit me @ https://t.me/responseWithBarcodeBot Description   This project is a Telegram bot that generates barcodes based on user input. It is a fork of the generate-qr-code-telegram-bot project and extends its functionality to create barcodes in addition to QR codes. The bot allows users to send text messages and receive barcode…

  • how to remove text under barcode @ python-barcode library

    how to remove text under barcode @ python-barcode library

    by

    in

    You should set `options` parameter on barcode.save object with {“writer_text”: False} basically it should look like: barcode.save(“barcode_file_name”, options={“writer_text”: False}). You can pass multiple options at once, example: import barcode import io from base64 import b64encode from barcode.writer import ImageWriter # Generate barcode object barcode_obj = barcode.Code128(str(“12363296”), writer=barcode.writer.ImageWriter()) writer_options = { “write_text”: False, # Disable writing…

  • AWS: botocore.exceptions.NoRegionError: You must specify a region.

    AWS: botocore.exceptions.NoRegionError: You must specify a region.

    by

    in

    solution: export AWS_DEFAULT_REGION=us-west-2

  • How to assert 2 simple functions return the same value in Python?

    How to assert 2 simple functions return the same value in Python?

    by

    in

    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?

    Python dict.get() vs dict[‘brackets’], which approach is better?

    by

    in

    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

    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

    Python Programming Language 3.7 Cheat Sheet Image for beginners and people who want to find out what’s new on Python 3.7