med-mastodon.com is one of the many independent Mastodon servers you can use to participate in the fediverse.
Medical community on Mastodon

Administered by:

Server stats:

410
active users

#fastapi

0 posts0 participants0 posts today
Continued thread

Un altre descobriment en aquest camí ha estat #Pydantic. Com podia viure programàticament parlant sense Pydantic?
Pydantic és una biblioteca de Python que serveix per validar i gestionar dades amb tipus. Et permet definir models (com classes) on s’especifica el tipus de cada camp, i automàticament valida i converteix les dades rebudes. Integrat a la perfecció amb fastAPI.

Continued thread

Totes les aplicacions client per Android funcionen amb #appy i el mateix passa amb les de iOS. Aquesta és la clau, volia aprofitar totes les apps existents per tant l'API havia de ser una copia de la de Mastodon però feta amb fastAPI, que ha resultat una tria excel·lent. fastAPI és brutal, fa tot i més i molt bé. I, a més, et genera automàticament la documentació sense ni preocupar-te per ella. Insisteixo, brutal.

Continued thread

L'estructura tècnica d'#appy funciona gràcies a Python, fastAPI, #Postgresql (base de dades) i #Redis (memòria cau).
Tot de manera asincrona per evitar punts de bloqueig, passen moltes coses en parall·lel, simultàniament, bàsic per a tenir fluïdesa tant en les interaccions amb altres servidors com amb les aplicacions client.
appy funciona bé fins i tot en una #Raspberry 4B, per tant també és una opció vàlida per a tenir el perfil fediversal auto gestionat i a casa.

Continued thread

Quan vaig posar en marxa mastodont.cat no en sabia res de Python i ActivityPub no existia (Mastodon funcionava a les hores amb el protocol Ostatus de GNU Social).
Qui podria pensar que acabaria programant el meu propi servidor? sí, estic content d'haver-ho aconseguit i de compartir el resultat amb la comunitat de programari lliure a codeberg.org/spla/appy
Queda feina encara però sí, ja ho considero un èxit 😃

Summary card of repository spla/appy
Codeberg.orgappya headless ActivityPub server written with Python and fastAPI.

Queden algorismes per polir, afegir funcionalitats com ara bloquejar o silenciar usuaris i servidors i depurar incidències però ja considero que #appy és un èxit.
Des de juny de l'any passat he estat (i estic) molt centrat en desenvolupar el meu propi servidor ActivityPub des de zero, sense copiar res de ningú, per pur plaer personal de superar reptes. He après molt pel camí, no és gens fàcil però he gaudit molt de cada fita.
Va ser tot un encert triar #Python i #fastAPI, van sobrats.

"Dependency Injection" a #fastAPI és un sistema molt fàcil i a l'hora molt potent d'evitar repetir el mateix codi en tots els punts finals (endpoints) de l'API.
En cadascun dels punts finals fas una crida a la funció que vulguis mitjançant el paràmetre "Depends", funció que verifica que es compleix el requisit necessari, en l'exemple, l'aplicació client ha d'enviar el token correcte, si no és així, la funció que executa Depends és l'encarregada de retornar l'error a l'app client.

kitfucoda.medium.com/writing-a

I've just finished writing up a deep dive into building a Telegram bot with a FastAPI web application, and it was quite the journey into asynchronous Python! 🐍

The project started with a desire to run chatbots across multiple platforms, but quickly evolved into a focused exploration of asyncio. I found myself wrestling with event loops, queues, and the nuances of asyncio.create_task vs. asyncio.to_thread. It became very clear that understanding the difference between concurrency and parallelism is absolutely crucial in this space. Clever scheduling can mitigate blocking, but over-scheduling will inevitably lead to performance issues.

Architectural considerations became a major focus. I learned firsthand that cramming everything into a single process, while tempting, isn't always the best approach. Separating processes for scalability and future enhancements is something I'll definitely keep in mind for future projects.

This project was a great learning experience, and I'm looking forward to applying these lessons to future projects. If you're interested in asyncio, webhooks, or building chatbots, I'd love to hear your thoughts!
#python #asyncio #telegrambot #fastapi #webdevelopment #programming #opentowork #fedihire

Medium · How to write an AsyncIO Telegram bot in Python - KitFu Coda - MediumBy KitFu Coda

Fun #Python #FastAPI problem today.

I was writing my own error catching middleware to force errors into a specific format.

It seems that returning a 204 - no content status from my API raises a HTTPException. This got caught in the error catcher and caused problems when suddenly some JSON content was generated.

Locating this problem was quite challenging.

After adding special "no content" handling, that problem went away.

If you write your own error handler, consider this case!