Problem: FastAPI doesn't accept JSON-encoded pydantic models in query strings. See #884.
Solution: Use json_param()
from the snippet below.
Usage example.
from fastapi import FastAPI
from pydantic import BaseModel
""" | |
A simple contrived example of a FastAPI application that heavily uses | |
the FastAPI dependency injection system. | |
Sample request http://127.0.0.1:9876/tasks?user_id=123456 | |
returns [{"id":1,"name":"Task 1","user":{"id":123456,"name":"John Doe"}}] | |
Dependency tree: | |
get_me() |
import requests | |
from requests.adapters import HTTPAdapter | |
from urllib3.util.retry import Retry | |
USER_AGENT = "My project (https://example.com)" | |
def get_default_session() -> requests.Session: | |
"""Return a request.Session() instance with reasonable defaults for retries. |
Problem: FastAPI doesn't accept JSON-encoded pydantic models in query strings. See #884.
Solution: Use json_param()
from the snippet below.
Usage example.
from fastapi import FastAPI
from pydantic import BaseModel
#!/usr/bin/env ipython -i | |
import datetime | |
import json | |
from typing import Optional | |
import sqlalchemy as sa | |
from sqlalchemy.orm import declarative_base, sessionmaker | |
from sqlalchemy.dialects.postgresql import JSONB | |
from pydantic import BaseModel, Field, parse_obj_as |
menu=$(curl -s 'https://www.facebook.com/SambaNaGrelha' | \ | |
rg -o 'Bom dia estimados clientes hoje para prato do dia temos.*?Fazemos entregas ao domicílio' | \ | |
head -n1 | html2text) | |
curl -s "https://api.telegram.org/bot$BOT_ID/sendMessage?chat_id=$CHAT_ID" -d text="$menu" > /dev/null |
#!/usr/bin/env python | |
""" | |
An ad-hoc script to analyze the percentage of the topic-specific questions for | |
each programming language. | |
For each language, the script downloads two pages and looks for the number of questions | |
in the title, like "NNN,NNN questions". For example, for "python" and | |
an extra tag "architecture", the script downloads | |
https://stackoverflow.com/questions/tagged/python and | |
https://stackoverflow.com/questions/tagged/python+architecture. |
import pandas as pd | |
from docxtpl import DocxTemplate | |
SHEET_URL='https://docs.google.com/spreadsheets/d/1Kvb5bmm2qZWEH4I5hJYZMEuIBU-CCw_ivyv_jjB1w4w/export?exportFormat=csv' | |
TEMPLATE = 'quote.docx' | |
def save_quote(quote_id): | |
df = pd.read_csv(SHEET_URL, index_col='QuoteID') | |
context = dict(df.loc[quote_id]) | |
doc = DocxTemplate(TEMPLATE) |
This is a simple implementation for TCP server and client. The server listens for the port 9090 of the localhost, receives messages from any connected clients, and sends them to all connected peers. The client is started with a username as an argument, reads in an infinite loop messages from the string, re-format them as "name > message\n" and send to the server. In a different async function it also waits for message from the server and prints the to the console.
Files:
aio_chat_client.py
: client implementationaio_chat_server.py
: server implementationDependencies: Python 3.6+ and aioconsole
Install aioconsole