{"catalogRevision":"cat_f13ab9a494120b5e","recipeId":"page:guides:fastapi:private-file-access","recipeRevision":"r1","canonicalPath":"/guides/fastapi/private-file-access","label":"Enforce private-file authorization for FastAPI","family":"Framework operation","summary":"Private file access for a FastAPI app on Ample. Verified on FastAPI: a role-to-document access model with negative tests (401, 403) and an authorized private-bucket round-trip (private=ok). Build and start: pip install into .ample/python from requirements.txt, then uvicorn from run.py reading PORT on the python-3.12 template.","representativeQueries":["Enforce private-file authorization for FastAPI","Where can I host Enforce private-file authorization built with FastAPI?","I need application identity integration, per-file access rules and negative authorization tests."],"breadcrumbIds":["discovery","stack","stack:frameworks","stack:framework-fastapi","page:guides:fastapi:private-file-access"],"breadcrumbs":[{"id":"discovery","label":"Agent hosting discovery","canonicalPath":"/discover/discovery","kind":"root"},{"id":"stack","label":"Frameworks and execution targets","canonicalPath":"/discover/stack","kind":"facet"},{"id":"stack:frameworks","label":"Frameworks","canonicalPath":"/discover/stack/frameworks","kind":"group"},{"id":"stack:framework-fastapi","label":"FastAPI","canonicalPath":"/discover/stack/framework-fastapi","kind":"atom"},{"id":"page:guides:fastapi:private-file-access","label":"Enforce private-file authorization for FastAPI","canonicalPath":"/guides/fastapi/private-file-access","kind":"recipe"}],"parentIds":["stack:framework-fastapi","intent:connect-app-to-storage","pattern:private-document-library"],"parents":[{"id":"stack:framework-fastapi","label":"FastAPI","canonicalPath":"/discover/stack/framework-fastapi","kind":"atom"},{"id":"intent:connect-app-to-storage","label":"Connect app to storage","canonicalPath":"/discover/intent/connect-app-to-storage","kind":"atom"},{"id":"pattern:private-document-library","label":"Private document library","canonicalPath":"/discover/pattern/private-document-library","kind":"atom"}],"resourceRequirements":["primitive:compute","primitive:postgres","primitive:s3-compatible-object-storage"],"infrastructureRequirements":[{"primitiveId":"primitive:compute","label":"Compute","canonicalPath":"/discover/primitive/compute","status":"verified","summary":"Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request; sizes are the priced VM sizes."},{"primitiveId":"primitive:postgres","label":"Postgres","canonicalPath":"/discover/primitive/postgres","status":"verified","summary":"Managed PostgreSQL 16 runs in its own microVM and is auto-provisioned when an app needs a database and no DATABASE_URL is supplied."},{"primitiveId":"primitive:s3-compatible-object-storage","label":"S3-compatible object storage","canonicalPath":"/discover/primitive/s3-compatible-object-storage","status":"verified","summary":"Buckets are S3-compatible with issued credentials; PutObject and GetObject are verified by canary. Other S3 operations are not verified."}],"framework":"FastAPI","workload":"Enforce private-file authorization","releaseStatus":"published","supportStatus":"verified","executionStatus":"ready","docsOnly":false,"prerequisites":["A FastAPI project (pip install into .ample/python from requirements.txt, then uvicorn from run.py reading PORT on the python-3.12 template)","A PostgreSQL driver reading DATABASE_URL at runtime","A bucket from `ample bucket create` with credentials passed as encrypted S3_* environment variables","An Ample account token with servers:write, databases:read, buckets:read"],"testedConfiguration":{"template":"python-3.12","runtime":"python","size":"s-1vcpu-1gb","install":"python3 -m pip install --target .ample/python -r requirements.txt","start":"PYTHONPATH=.ample/python:${PYTHONPATH:-} python3 run.py"},"inputSchema":{"additionalProperties":false,"properties":{"env":{"description":"Encrypted environment variables","items":{"pattern":"^[A-Z][A-Z0-9_]*=.*$","type":"string"},"maxItems":50,"type":"array"},"name":{"description":"App name","maxLength":63,"minLength":1,"pattern":"^[a-z0-9-]+$","type":"string"},"path":{"description":"Project directory or ample.toml service","maxLength":512,"minLength":1,"type":"string"},"release_command":{"description":"Migration command run before activation","maxLength":512,"type":"string"},"start":{"description":"Start command","maxLength":512,"type":"string"}},"required":["env","name","path","start"],"type":"object"},"outputSchema":null,"workflowSteps":[{"title":"Build and start","body":"pip install into .ample/python from requirements.txt, then uvicorn from run.py reading PORT on the python-3.12 template; the server must bind 0.0.0.0 on PORT."},{"title":"Create the bucket and pass its credentials","body":"Create it once with `ample bucket create`, then pass endpoint, region, bucket and keys with --env; use path-style addressing.","command":"ample deploy . --name <app-name> --public --start \"python3 run.py\" --env S3_ENDPOINT=... --env S3_REGION=... --env S3_BUCKET=... --env S3_ACCESS_KEY_ID=... --env S3_SECRET_ACCESS_KEY=..."},{"title":"Authorize before touching storage","body":"Return 401 for unauthenticated requests and 403 for the wrong role; keep the bucket unpublished and stream objects through the app."},{"title":"Verify","body":"Fetch the live URL and /p/private-document-library on the example; on failure read the build and runtime logs.","command":"ample logs <deployment_id> --kind build"}],"examples":[{"title":"FastAPI pattern fixture","description":"Verified private file access on FastAPI.","sourceRef":"tests/deploy-canaries/fastapi-patterns"}],"successChecks":[{"description":"app responds on its public URL","kind":"http_get","path":"/","expect":"ample canary fastapi patterns"},{"description":"private-document-library check from the example","kind":"http_get","path":"/p/private-document-library","expect":"see the pattern fixture checks"}],"limitations":["Verified on the python-3.12 template at s-1vcpu-1gb; other sizes and FastAPI major versions are not verified.","Region, compliance attestations and request-duration limits are unknown and not claimed.","Managed PostgreSQL 16 only; extensions, connection limits and backup or restore procedures are not verified.","PutObject and GetObject with path-style addressing are verified; other S3 operations are not."],"costEstimate":{"currency":"USD","monthlyAmount":10.0,"authoritative":true,"basis":"size prices from pricing.toml (loaded by the API) at build revision 752d2a7584688a5d233b2c53d38307d289b04d3e","components":[{"name":"app server","size":"s-1vcpu-1gb","quantity":1.0,"monthlyAmount":5.0},{"name":"managed PostgreSQL database","size":"s-1vcpu-1gb","quantity":1.0,"monthlyAmount":5.0}],"note":"Always-on monthly price of the tested sizes; apps auto-pause when idle. Buckets are allocation-priced per quota and not included."},"evidenceSummary":[{"kind":"canary_run","summary":"FastAPI pattern fixture deployed on Ample (pip install into .ample/python from requirements.txt, then uvicorn from run.py reading PORT on the python-3.12 template); for this guide: a role-to-document access model with negative tests (401, 403) and an authorized private-bucket round-trip (private=ok).","observedAt":"2026-09-21T01:14:18Z","implementationRevision":"50dbac567d2c5cc8e55e6c748a646be0025d9cfb (CLI 0.1.21)","expiresAt":"2027-03-20T01:14:18Z","scope":{"checks":["/p/private-document-library"],"template":"python-3.12"}}],"lastVerifiedAt":"2026-09-21T01:14:18Z","mcpBinding":{"registryRef":"mcp:ample_deploy","toolName":"ample_deploy","schemaHash":"876465fce906da0c224d62961d3343064108ebe30af80cf1b87094974e948853","observedAt":"2026-09-22T00:31:22.774679+00:00","implementationRevision":"e6446ceea69b","requiredScopes":["servers:write","databases:read","buckets:read"],"bindingState":"current"},"unknowns":["region availability is unknown until a verified region fact is recorded","compliance attestations are unknown; none are claimed"],"formats":{"html":"https://ample.computer/guides/fastapi/private-file-access","markdown":"https://ample.computer/guides/fastapi/private-file-access.md","json":"https://api.ample.computer/v1/catalog/recipes/page%3Aguides%3Afastapi%3Aprivate-file-access"},"nextActions":[{"actionId":"browse-catalog","label":"Browse the catalog index","operationId":"catalog_index","method":"GET","relativePath":"/v1/catalog","origin":"api","parameters":{},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"search-recipes","label":"Search published recipes by intent, stack and constraints","operationId":"search_recipes","method":"POST","relativePath":"/v1/catalog/search","origin":"api","parameters":{"body":{"limit":5,"query":"Enforce private-file authorization for FastAPI"}},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"plan:page:guides:fastapi:private-file-access","label":"Prepare a side-effect-free deployment plan for an authorized project","operationId":"plan_deployment","method":"POST","relativePath":"/v1/catalog/plan","origin":"api","parameters":{"body":{"inputs":{},"projectId":"<workspace or server id you own>","recipeId":"page:guides:fastapi:private-file-access","recipeRevision":"r1"}},"requiresAuthentication":true,"requiresApproval":false},{"actionId":"auth-setup","label":"Read the existing agent authentication setup","operationId":"existing_auth_setup","method":"GET","relativePath":"/mcp/setup","origin":"api","parameters":{},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:stack:framework-fastapi","label":"Browse FastAPI","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/stack%3Aframework-fastapi","origin":"api","parameters":{"nodeId":"stack:framework-fastapi"},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:intent:connect-app-to-storage","label":"Browse Connect app to storage","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/intent%3Aconnect-app-to-storage","origin":"api","parameters":{"nodeId":"intent:connect-app-to-storage"},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:pattern:private-document-library","label":"Browse Private document library","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/pattern%3Aprivate-document-library","origin":"api","parameters":{"nodeId":"pattern:private-document-library"},"requiresAuthentication":false,"requiresApproval":false}]}