Python functions as REST objects, with clustering, load balancing and state replication; no containers or orchestration.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-primitive.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-primitive.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-primitive.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Dan Q Consolidate duplicate QUICKSTARTs on the top-level file 503f830 7 months ago History
objects.py · 1.3 KB · 49 lines
1"""
2API handler for listing all objects
3
4GET /objects - List all available objects
5"""
6import json
7from pathlib import Path
8from dbbasic_web.responses import json as json_response, json_error
9
10
11def GET(request):
12 """List all available objects"""
13 # Find all .py files in examples directory
14 examples_dir = Path('examples')
15
16 if not examples_dir.exists():
17 return json_response(json.dumps({
18 'status': 'ok',
19 'objects': [],
20 'count': 0,
21 'message': 'No objects found (examples directory does not exist)',
22 }))
23
24 objects = []
25
26 # Scan for .py files
27 for py_file in examples_dir.rglob('*.py'):
28 # Skip __init__.py and __pycache__
29 if py_file.name == '__init__.py' or '__pycache__' in str(py_file):
30 continue
31
32 # Get relative path from examples/
33 rel_path = py_file.relative_to(examples_dir)
34 object_id = str(rel_path).replace('.py', '').replace('/', '_')
35
36 objects.append({
37 'object_id': object_id,
38 'path': str(rel_path),
39 'file': str(py_file),
40 })
41
42 # Sort by object_id
43 objects.sort(key=lambda x: x['object_id'])
44
45 return json_response(json.dumps({
46 'status': 'ok',
47 'objects': objects,
48 'count': len(objects),
49 }))