Skip to content

Instantly share code, notes, and snippets.

Avatar

Francesco Bartoli francbartoli

View GitHub Profile
@francbartoli
francbartoli / diff_strings.py
Created Aug 1, 2019 — forked from ines/diff_strings.py
Print colored visual diff in Python
View diff_strings.py
import difflib
import wasabi
def diff_strings(a, b):
output = []
matcher = difflib.SequenceMatcher(None, a, b)
for opcode, a0, a1, b0, b1 in matcher.get_opcodes():
if opcode == "equal":
output.append(a[a0:a1])
elif opcode == "insert":
View keybase.md

Keybase proof

I hereby claim:

  • I am francbartoli on github.
  • I am francbartoli (https://keybase.io/francbartoli) on keybase.
  • I have a public key ASAfiWwwrRVTyUk8LJduV6TMkI8gRzNenpCyeBpXI63FCAo

To claim this, I am signing this object:

View fastapi_basic_imports.py
from typing import Optional
import base64
from passlib.context import CryptContext
from datetime import datetime, timedelta
import jwt
from jwt import PyJWTError
from pydantic import BaseModel
View fastapi_api_key.py
from fastapi import Security, Depends, FastAPI, HTTPException
from fastapi.security.api_key import APIKeyQuery, APIKeyCookie, APIKeyHeader, APIKey
from fastapi.openapi.docs import get_swagger_ui_html
from fastapi.openapi.utils import get_openapi
from starlette.status import HTTP_403_FORBIDDEN
from starlette.responses import RedirectResponse, JSONResponse
API_KEY = "1234567asdfgh"
API_KEY_NAME = "access_token"
View fastapi_google_authentication_imports.py
from typing import Optional
from datetime import datetime, timedelta
import jwt
from jwt import PyJWTError
from fastapi import Depends, FastAPI, HTTPException
from fastapi.encoders import jsonable_encoder
from fastapi.security.oauth2 import (
OAuth2,
View fastapi_basic.py
from typing import Optional
import base64
from passlib.context import CryptContext
from datetime import datetime, timedelta
import jwt
from jwt import PyJWTError
from pydantic import BaseModel
@francbartoli
francbartoli / fastapi_demo.py
Created Jun 2, 2019 — forked from wshayes/fastapi_demo.py
[FastAPI Single File Demo] Example fastapi single file testable example #fastapi
View fastapi_demo.py
import logging
from fastapi import FastAPI
from starlette.responses import RedirectResponse
from starlette.testclient import TestClient
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
app = FastAPI()
View fastapi_api_key_imports.py
from fastapi import Security, Depends, FastAPI, HTTPException
from fastapi.security.api_key import APIKeyQuery, APIKeyCookie, APIKeyHeader, APIKey
from fastapi.openapi.docs import get_swagger_ui_html
from fastapi.openapi.utils import get_openapi
from starlette.status import HTTP_403_FORBIDDEN
from starlette.responses import RedirectResponse, JSONResponse
@francbartoli
francbartoli / demo.py
Created Jun 2, 2019 — forked from wshayes/demo.py
[Websocket demo for fastapi] example of broadcast using websockets for fastapi #fastapi #websockets
View demo.py
# From https://github.com/tiangolo/fastapi/issues/258
from typing import List
from fastapi import FastAPI
from starlette.responses import HTMLResponse
from starlette.websockets import WebSocket, WebSocketDisconnect
app = FastAPI()
@francbartoli
francbartoli / code_samples.py
Created Jun 2, 2019 — forked from wshayes/code_samples.py
[FastAPI code samples] #fastapi
View code_samples.py
# Detecting multiple request methods
@app.api_route(methods=["PATCH", "POST"])
OR
@app.get('/profile')
@app.post('/profile')
async def profile(request: Request, api_key: str = Depends(get_api_key)):
if request.method == 'POST':