I’m a software developer and open-source enthusiast.
Feel free to check my projects on GitHub and get in touch with me.
I’m a software developer and open-source enthusiast.
Feel free to check my projects on GitHub and get in touch with me.
Async tests and fixtures Pytest already has the official pytest-asyncio plugin which allows you to write async tests and fixtures. According to pytest-asyncio docs, you can have an async test with an async fixture like this: from typing import Any, AsyncGenerator import pytest import pytest_asyncio from httpx import AsyncClient @pytest_asyncio.fixture async def client() -> AsyncGenerator[AsyncClient, Any]: async with AsyncClient() as c: yield c @pytest.mark.asyncio async def test_api_call(client: AsyncClient) -> None: response = await client....
Summary Recently I was working on a project that integrated with some internal and external APIs using HTTP requests. You probably have heard about or worked with the requests library in Python which is probably the de-facto HTTP client package which is much easier to work with compared to the built-in HTTP module of Python. The previous implementation in our project was using the requests library and for each new request it did something like requests....
Intro If you are already familiar with Pydantic, one of the useful components of Pydantic is the Settings Management. This will allow you to read settings variables from different sources and parse and validate them into class(es) using Pydantic. Let’s see a minimal example. First we need to set up the variable: $ export API_KEY=xxx And then we can read it into the Settings class with: from pydantic import BaseSettings class Settings(BaseSettings): api_key: str print(Settings()....
Intro From AWS website: AWS Lambda is a serverless, event-driven compute service that lets you run code for virtually any type of application or backend service without provisioning or managing servers. Even though it’s not required to use a web framework like FastAPI or Django to start using AWS Lambda, often it is the case you have an existing project or you want to use a framework for useful features....
Use-case It’s very common for projects to do JSON logging if you are working with third-party tools or open-source projects like Logstash to process your logs. These tools usually need more complex filtering on the structured data, so using JSON is preferred there. We also wanted to integrate with a third-party tool at work and we needed to add the JSON formatting logs in our projects. I will not go into the details of why or why not you should decide JSON logging, as each approach will have it’s pros and cons....