Skip to content

Python ​

pip install flattype gives Python backends the same format, byte for byte. It has no dependencies and supports Python 3.9+. Thousands of shared test cases check that both languages write and read exactly the same text, errors included.

python
import flattype
from fastapi import FastAPI
from flattype.asgi import FlatMiddleware

flattype.encode({"name": "John", "age": 30})  # "name: John\nage: 30"
flattype.decode("name: John\nage: 30")  # {'name': 'John', 'age': 30}

app = FastAPI()
app.add_middleware(FlatMiddleware)  # JSON responses answer in Flat Notation when the client asks

So a FastAPI backend and a React frontend using useFlat talk Flat Notation with one line on each side. flattype.ai has to_prompt, from_model_output and count_tokens for Claude. See the Python README and the FastAPI example.

Released under the MIT License.