Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions litestar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Litestar

Created By: Jacob Coffee

# About
This is a starter template in Python for building a [Litestar](https://litestar.dev) application

# Try it out
<a href="https://idx.google.com/new?template=https://github.com/project-idx/community-templates/tree/main/litestar">
<picture>
<source
media="(prefers-color-scheme: dark)"
srcset="https://cdn.idx.dev/btn/open_dark_32.svg">
<source
media="(prefers-color-scheme: light)"
srcset="https://cdn.idx.dev/btn/open_light_32.svg">
<img
height="32"
alt="Open in IDX"
src="https://cdn.idx.dev/btn/open_purple_32.svg">
</picture>
</a>
36 changes: 36 additions & 0 deletions litestar/dev.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{ pkgs, ... }: {
# Which nixpkgs channel to use.
channel = "stable-24.05"; # or "unstable"
# Use https://search.nixos.org/packages to find packages
packages = [
pkgs.python3
pkgs.python312Packages.pip
pkgs.python312Packages.litestar
pkgs.python312Packages.uvicorn
];
# Sets environment variables in the workspace
env = {};
idx = {
previews = {
enable = true;
previews = {
web = {
command = [ "./devserver.sh" ];
env = { PORT = "$PORT"; };
manager = "web";
};
};
};
# Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
extensions = [ "ms-python.python" "rangav.vscode-thunder-client" ];
workspace = {
# Runs when a workspace is first created with this `dev.nix` file
onCreate = {
install =
"python -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt";
# Open editors for the following files by default, if they exist:
default.openFiles = [ "app.py" ];
};
};
};
}
19 changes: 19 additions & 0 deletions litestar/dev/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from litestar import Litestar, get
from litestar.config.cors import CORSConfig
import uvicorn

@get("/")
async def home() -> dict:
return {"message": "Now you can effortlessly create a REST API with Litestar!"}

cors_config = CORSConfig(
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

app = Litestar(route_handlers=[home], cors_config=cors_config)

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0")
3 changes: 3 additions & 0 deletions litestar/dev/devserver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
source .venv/bin/activate
litestar run --debug --reload
3 changes: 3 additions & 0 deletions litestar/dev/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pip
litestar
uvicorn
11 changes: 11 additions & 0 deletions litestar/idx-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Litestar",
"description": "Effortlessly build performant APIs with Litestar - The powerful, lightweight and flexible ASGI framework",
"categories": [
"Web app",
"Backend"
],
"icon": "https://github.com/litestar-org/branding/blob/6a4f90f42dbc5412c39a138fb5b8e6a3cd489590/assets/Branding%20-%20SVG%20-%20Transparent/Logo%20-%20Blue%20and%20Yellow.svg",
"website": "https://litestar.dev/",
"publisher": "Jacob Coffee"
}
16 changes: 16 additions & 0 deletions litestar/idx-template.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ pkgs, ... }: {
packages = [
pkgs.python3
pkgs.python312Packages.pip
pkgs.python312Packages.litestar
pkgs.python312Packages.uvicorn
];
bootstrap = ''
mkdir "$out"
mkdir -p "$out/.idx/"
cp -rf ${./dev.nix} "$out/.idx/dev.nix"
shopt -s dotglob; cp -r ${./dev}/* "$out"
chmod -R +w "$out"
chmod +rwx "$out/devserver.sh"
'';
}