Python Snippets
Python snippets for Zed IDE. A collection of python snippets to improve your development speed.
How to install
With Forge Super installed, the button above opens the app on this extension, where you press Install. Nothing is installed until you do.
You can also open the Extensions panel in the app and search for Python Snippets. The extension's id is python-snippets.
Don't have Forge Super yet? Download it here.
README
From the extension's repository, written by its authors and not by Mentenaz. See the source.
Python Snippets for Zed IDE
A collection of Python snippets for the Zed IDE to improve your development speed and productivity.
Features
This extension provides a comprehensive set of snippets for Python development, including:
- Package and import declarations
- Control structures (if, for, while, try/except)
- Function and method declarations
- Modern Python features (f-strings, type hints, dataclasses)
- Framework-specific snippets (FastAPI, Pydantic, Typer)
- Database ORM snippets (SQLAlchemy)
- Testing helpers (unittest, pytest)
- And much more!
Installation
Method 1
- Go to Extensions menu in Zed IDE
- Search for "python-snippets"
- Click "Install"
Method 2
- Clone this repo:
git clone https://github.com/jctosta/python-zed-snippets.git
- Go to Extensions menu in Zed IDE
- Click "Install Dev Extension"
- Select the folder you cloned
Usage
To make snippets appear at the top of the completion list in Zed, add this setting to your Zed settings file:
{
"snippet_sort_order": "top"
}
Start typing the snippet prefix (e.g., def) in a Python file and press Tab to expand the snippet.
Available Snippets
| Prefix | Description |
|---|---|
im | Import module |
ifm | Import from module |
main | if __name__ == "__main__" entrypoint |
def | Function definition |
class | Class definition |
prop | Property (getter) |
meth | Method definition |
for | For loop |
while | While loop |
if | If statement |
ifelse | If-else statement |
elif | Elif block |
try | Try-except block |
tryf | Try-except-finally block |
with | With context manager |
ctx | Context manager class |
deco | Decorator function |
lambda | Lambda expression |
lc | List comprehension |
print | Print statement |
fs | F-string |
logi | Logging info message |
logd | Logging debug message |
| FastAPI | |
fastapi-app | FastAPI minimal app |
fastapi-route | FastAPI route handler |
fastapi-dep | FastAPI dependency function |
| Pydantic | |
pydbase | Pydantic BaseModel class |
pydval | Pydantic validator |
| Typer | |
typer-app | Typer CLI application setup |
| SQLAlchemy | |
sa-base | SQLAlchemy Base import |
sa-model | SQLAlchemy Model |
sa-session | SQLAlchemy session setup |
| unittest | |
ut | Unittest TestCase |
utmain | Unittest main entrypoint |
| pytest | |
pt | Pytest test function |
ptp | Pytest parametrize test |
ptfix | Pytest fixture |
pttable | Pytest table-driven test (parametrize) |
| Asyncio | |
adef | Async coroutine definition |
atg | Async TaskGroup context manager definition |
amain | Main entrypoint with asyncio.run function |
| Misc | |
dc | Python dataclass |
hintf | Function with type hints |
doc | Function docstring template |
Examples
Function definition
Type def and press Tab:
def func(args):
# Your code here
If statement
Type if and press Tab:
if condition:
# Your code here
Class with property and method
Type class, then prop, and meth inside the class, and press Tab each time:
class MyClass(object):
def __init__(self, value):
self._value = value
@property
def value(self):
return self._value
def my_method(self, arg):
# Your code here
FastAPI minimal app
Type fastapi-app and press Tab:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
Pytest test function
Type pt and press Tab:
def test_func():
# Your test code here
Dataclass
Type dc and press Tab:
from dataclasses import dataclass
@dataclass
class Name:
field: type
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Author
Carlos Tosta - jctosta86@gmail.com
Acknowledgments
This extension is inspired by and based on the excellent Go Snippets for Zed IDE created by Ayberk Gezer. Many of the snippet ideas, naming conventions, and file structure for this Python extension are derived from that project.
Special thanks to Ayberk Gezer for providing a solid foundation and reference implementation.