Skip to content

Commit 4206be3

Browse files
committed
set up python demo
1 parent 89e0eda commit 4206be3

23 files changed

Lines changed: 2698 additions & 0 deletions

.env.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# set API TOKEN so that the cli is authorized to use the public api
2+
CS_TOKEN=
3+
TEAM_ID=

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.env
2+
3+
.github/*

backend/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
junit/*
2+
coverage.xml
3+
pytest-coverage.txt
4+
.coverage
5+
6+
__pycache__/*

backend/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12.9

backend/README.md

Whitespace-only changes.

backend/app.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from typing import Dict
2+
from fastapi import FastAPI
3+
from fastapi.middleware.cors import CORSMiddleware
4+
import numpy as np
5+
import pandas as pd
6+
7+
app = FastAPI()
8+
app.add_middleware(
9+
CORSMiddleware,
10+
allow_origins=["*codesphere.com"],
11+
allow_credentials=True,
12+
allow_methods=["*"],
13+
allow_headers=["*"],
14+
)
15+
16+
@app.get("/")
17+
def read_root():
18+
return {"Status": "FastAPI Backend is running"}
19+
20+
21+
@app.get("/api/data")
22+
def get_chart_data(points: int = 30) -> Dict:
23+
test_data = create_data(points)
24+
return test_data
25+
26+
def create_data(points: int) -> Dict:
27+
chart_data = pd.DataFrame(
28+
np.random.randn(points, 2),
29+
columns=['A', 'B']
30+
)
31+
return chart_data.to_dict(orient='split')
32+
33+
if __name__ == "__main__":
34+
pass
35+
36+

backend/doc.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from fastapi import FastAPI
2+
from fastapi.openapi.utils import get_openapi
3+
4+
from app import app
5+
6+
app_docs = FastAPI(
7+
title=f"Dokumentation für '{app.title}'",
8+
version=app.version,
9+
root_path="/api",
10+
docs_url="/docs",
11+
redoc_url="/redoc"
12+
)
13+
14+
openapi_schema = get_openapi(
15+
title=app_docs.title,
16+
version=app_docs.version,
17+
routes=app.routes,
18+
)
19+
20+
app_docs.openapi_schema = openapi_schema
21+
22+
def custom_openapi():
23+
return app_docs.openapi_schema
24+
25+
app_docs.openapi = custom_openapi

backend/pyproject.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[project]
2+
name = "backend"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.12.9"
7+
dependencies = [
8+
"fastapi[all]>=0.115.12",
9+
"numpy>=2.3.0",
10+
"pandas>=2.3.0",
11+
"pytest-cov>=6.1.1",
12+
]
13+
14+
[dependency-groups]
15+
dev = [
16+
"bandit>=1.8.3",
17+
"pytest>=8.4.0",
18+
]
19+
20+
[tool.pytest.ini_options]
21+
testpaths = ["tests"]
22+
pythonpath = [
23+
"."
24+
]
25+
python_files = "test_*.py *_test.py"
26+
python_functions = "test_*"
27+
python_classes = "Test*"
28+
29+
[tool.coverage.run]
30+
source = ["api", "handler", "tasks"]
31+
branch = true
32+
omit = [
33+
"migrations/*",
34+
"models/*",
35+
"templates/*",
36+
"*/__main__.py",
37+
"tests/*",
38+
".venv/*",
39+
"__init__.py"
40+
]
41+
42+
[tool.coverage.report]
43+
show_missing = true
44+
exclude_lines = [
45+
"pragma: no cover",
46+
"if __name__ == .__main__.:",
47+
"raise NotImplementedError",
48+
"@(abc\\.)?abstractmethod",
49+
"def __repr__",
50+
"def __str__",
51+
]
52+
include_namespace_packages = true
53+
54+
[tool.coverage.html]
55+
directory = "test-results"
56+
57+
[tool.bandit]
58+
targets = ["app.py"]
59+
exclude_dirs = ["tests", ".venv", ".uv"]
60+
skips = ["B101"]
7.93 KB
Binary file not shown.

backend/tests/conftest.py

Whitespace-only changes.

0 commit comments

Comments
 (0)