Row-Level Security with SQLAlchemy

With Row Level security (RLS) you manage the access control at the row level within a database instead of the application. Row-Level Security allows you to define policies that determine which rows of data a particular user or role can access within a given table. Postgres Tables For this demonstration we create a simple setup with a User table and a Item table using SQLAlchemy 2.0: from sqlalchemy import Column, ForeignKey, Integer, String, create_engine, text from sqlalchemy....

<span title='2024-01-31 01:26:43 +0000 UTC'>January 31, 2024</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;562 words&nbsp;·&nbsp;Joost

Obfuscate Python

this post is under construction – I have the approaches here but need some time to also share the experience… How to obscure some Python code from anyone running the code? I am no expert here but I have tried a few things and will give my steps and recommendations here. Have a main.py with a simple helloworld FastAPI in this case. There is also an /error endpoint to see how much source code is returned in the logs....

<span title='2023-11-06 01:26:43 +0000 UTC'>November 6, 2023</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;289 words&nbsp;·&nbsp;Joost

Limit Concurrency in AsyncIO

You can run multiple async tasks simultaneously in Python using the asyncio native library. This allows you to create and manage asynchronous tasks, such as coroutines, and run them concurrently. Let’s have the following async method, that counts to the length of the given name and returns the name. import asyncio from typing import Awaitable async def count_word(name: str) -> Awaitable[str]: if len(name) > 8: raise ValueError(f"{name} is too long...") for ii in range(len(name)): print(name, ii) await asyncio....

<span title='2023-10-23 11:37:35 +0100 +0100'>October 23, 2023</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;530 words&nbsp;·&nbsp;Joost

Summarize large files - an introduction

ChatPDF providers, where you can question large files with large language models (LLM’s), are sprouting like mushrooms. The technique is mainly based on vector embedding with a vector index or vector database; based on the question, semantically relevant chunks from the file are provided to the LLM so it can compose an answer. While this technique is cool, it is limited when you ask a question that spans the entire text, such as generating a summary, since that requires not a couple of chunks, but the full text....

<span title='2023-07-31 11:37:35 +0100 +0100'>July 31, 2023</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;716 words&nbsp;·&nbsp;Joost

Async method decorator

Had a complete headache trying to figure out how a decorator as a class can maintain the possible async properties of a method. The solution is actually very simple. When called, use inspect.iscoroutinefunction to check whether it is a coroutine, and return again an async method! The example adds given paths to a registry, import inspect from functools import wraps paths_registry = [] class route(object): def __init__(self, path: str, **kwargs) -> None: self....

<span title='2021-09-24 04:07:47 +0000 UTC'>September 24, 2021</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;131 words&nbsp;·&nbsp;Joost