Starlette 1.0: The Rise of a Powerful Yet Overlooked Python Framework
Starlette 1.0: A Turning Point for the Python Framework
Starlette 1.0 has just made its debut on the tech scene, marking a significant turning point for this Python framework. Although its name is not as widely recognized as others, Starlette is actually the backbone of FastAPI, a framework that has captured the attention of many developers due to its speed and efficiency. This relative obscurity of Starlette contrasts with the massive enthusiasm surrounding FastAPI, overshadowing Starlette's importance in the Python ecosystem.
Kim Christie initiated the development of Starlette in 2018, and it quickly became a favorite among next-generation ASGI frameworks for Python. In addition to Starlette, Kim Christie is also known for his role in developing Django REST Framework, another essential tool for Python developers. Despite Starlette's potential, this framework was not integrated into the Datasette project due to a lack of stability guarantees at the time. The goal was to ensure a stable API for Datasette plugins, a project that, despite numerous alpha versions, has yet to reach its own version 1.0.
Marcelo Trylesinski announced that Starlette and Uvicorn would be transferred to their GitHub account, acknowledging their many years of contributions and facilitating their acquisition of funding for these projects.
What's New in Version 1.0
The 1.0 version of Starlette introduces substantial changes compared to previous versions. The release notes for 1.0.0rc1, published in February, detail these evolutions. One of the most significant changes concerns application lifecycle management. Previously, developers used the on_startup and on_shutdown parameters to manage execution at startup and shutdown. Now, an asynchronous context manager is used for this task, offering a more modern and flexible approach.
@contextlib.asynccontextmanager
async def lifespan(app):
async with some_async_resource():
print("Running on startup!")
print("Running on shutdown!")
For those discovering Starlette, it presents itself as a natural fusion between Flask and Django, utilizing asyncio to provide a smooth and efficient development experience. This feature makes it easier to create functional Starlette applications from simple prompts, a major asset for language models like LLMs.
Le brief IA que les pros lisent chaque soir
Les 7 actus IA du jour, décryptées en 5 min. Gratuit.
Inclus dès l'inscription : notre sélection des meilleurs guides & comparatifs IA.
Choisissez votre rythme
Gratuit · Pas de spam · Désabonnement en 1 clic
Challenges and Solutions with LLMs
However, one challenge remains: the compatibility of code generated by language models with the new version 1.0. If the models were trained on earlier versions, how can they produce code compatible with the latest version? This question was explored by developing a specific skill.
Skill Development with Claude
Claude, a chat agent on claude.ai, has built-in skills, including the ability to create new skills. A chat session was started with Claude to test this feature:
- Claude was asked to clone Starlette from GitHub, with the specification that it was version 1.0.
- Next, the creation of a markdown skill document for this version was requested, including code examples for each feature.
Without even indicating the location of the repository, Claude executed git clone https://github.com/encode/starlette.git. Although this was the old name of the repository, GitHub automatically handles redirects, allowing the operation to proceed smoothly.
The resulting skill document seemed very comprehensive. A new button, not seen before, appeared at the top, titled "Copy to your skills." It was clicked, and now the regular conversation with Claude has access to this skill!
Creating a Task Management Application
In a new conversation, Claude was asked to create a task management application using Starlette. The application was to include projects, tasks, comments, and labels. Claude responded by developing a simplified clone of GitHub Issues, using Starlette 1.0, an SQLite database via aiosqlite, and a Jinja2 template.
Claude also tested the application autonomously:
cd /home/claude/taskflow && timeout 5 python -c "
from database import init_db
asyncio.run(init_db())
print('Database initialized successfully')
pip install httpx --break-system-packages -q \
&& cd /home/claude/taskflow && \
from starlette.testclient import TestClient
from main import app
client = TestClient(app)
r = client.get('/api/stats')
print('Stats:', r.json())
r = client.get('/api/projects')
print('Projects:', len(r.json()), 'found')
r = client.get('/api/tasks')
print('Tasks:', len(r.json()), 'found')
r = client.get('/api/labels')
print('Labels:', len(r.json()), 'found')
r = client.get('/api/tasks/1')
print(f'Task 1: "{t["title"]}" - {len(t["comments"])} comments, {len(t["labels"])} labels')
r = client.post('/api/tasks', json={'title':'Test task','project_id':1,'priority':'high','label_ids':[1,2]})
print('Task created:', r.status_code, r.json()['title'])
r = client.post('/api/comments', json={'task_id':1,'content':'Test comment'})
print('Comment created:', r.status_code)
r = client.get('/')
print('Homepage:', r.status_code, '- length:', len(r.text))
print('\nAll tests passed!'
This experience demonstrates that Claude, as a coding agent, is capable not only of writing code but also of testing it effectively.
Brief IA — L'actualité IA en français
L'essentiel de l'actualité de l'intelligence artificielle, décrypté et expliqué chaque jour.