{"id":15527296,"url":"https://github.com/voltane-eu/djfapi","last_synced_at":"2025-04-23T12:27:31.666Z","repository":{"id":45552761,"uuid":"453839106","full_name":"Voltane-EU/djfapi","owner":"Voltane-EU","description":"Utilities to integrate fastapi with django orm","archived":false,"fork":false,"pushed_at":"2025-04-06T07:24:35.000Z","size":184,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T07:35:01.390Z","etag":null,"topics":["django","fastapi","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/djfapi/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Voltane-EU.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-31T00:32:00.000Z","updated_at":"2025-04-06T07:23:31.000Z","dependencies_parsed_at":"2025-03-05T13:36:17.934Z","dependency_job_id":"6895605c-dee9-4b48-b3d6-9d7de535af1f","html_url":"https://github.com/Voltane-EU/djfapi","commit_stats":{"total_commits":57,"total_committers":2,"mean_commits":28.5,"dds":"0.19298245614035092","last_synced_commit":"147133b041f1305090ae81c49d58b7b752950e57"},"previous_names":[],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Voltane-EU%2Fdjfapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Voltane-EU%2Fdjfapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Voltane-EU%2Fdjfapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Voltane-EU%2Fdjfapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Voltane-EU","download_url":"https://codeload.github.com/Voltane-EU/djfapi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250433129,"owners_count":21429812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","fastapi","python"],"created_at":"2024-10-02T11:05:25.427Z","updated_at":"2025-04-23T12:27:31.643Z","avatar_url":"https://github.com/Voltane-EU.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# djfapi\n\nA utility library to integrate and use fastapi with the django orm.\n\n## 🚧 This project is WIP and is subject to change at any time\n\nThis project is currently in the alpha state, even though it can be used in production with some caution. Make sure to fix the version in your requirements.txt and review changes frequently.\n\n## Installation\n\n`pip install djfapi`\n\n## Features\n\n### Sentry\n\nProvides optional sentry integration.\n\n### djdantic usage\n\nSee [djdantic](https://github.com/Voltane-EU/djdantic) for schema usage.\n\n### Automatic Route Generation\n\nDeclare routes without having to write routes using the `djfapi.routing.django.DjangoRouterSchema`.\n\nThe `DjangoRouterSchema` will supply a router, which just has to be included in the FastAPI app.\n\n#### Example for Routes\n\n```python\nfrom djfapi.routing.django import DjangoRouterSchema, SecurityScopes\n\n\ntransaction_token = JWTToken(scheme_name=\"Transaction Token\")\n\n\ndef company_objects_filter(access: Access) -\u003e Q:\n    q = Q(tenant_id=access.tenant_id)\n    if access.scope.selector != 'any':\n        q \u0026= Q(employees__user_id=access.user_id, employees__type__in=[models.Employee.EmployeeType.OWNER, models.Employee.EmployeeType.ADMIN])\n\n    return q\n\n\nrouter = DjangoRouterSchema(\n    name='companies',\n    model=models.Company,\n    get=schemas.response.Company,\n    create=schemas.request.CompanyCreate,\n    update=schemas.request.CompanyUpdate,\n    security=transaction_token,\n    security_scopes=SecurityScopes(\n        get=['business.companies.read.any', 'business.companies.read.own',],\n        post=['business.companies.create',],\n        patch=['business.companies.update.any', 'business.companies.update.own',],\n        put=['business.companies.update.any', 'business.companies.update.own',],\n        delete=['business.companies.delete.any', 'business.companies.delete.own',],\n    ),\n    objects_filter=company_objects_filter,\n    children=[\n        DjangoRouterSchema(\n            name='departments',\n            model=models.CompanyDepartment,\n            get=schemas.response.CompanyDepartment,\n            create=schemas.request.CompanyDepartmentCreate,\n            update=schemas.request.CompanyDepartmentUpdate,\n            children=[\n                DjangoRouterSchema(\n                    name='teams',\n                    model=models.CompanyDepartmentTeam,\n                    get=schemas.response.CompanyDepartmentTeam,\n                    create=schemas.request.CompanyDepartmentTeamCreate,\n                    update=schemas.request.CompanyDepartmentTeamUpdate,\n                ),\n            ]\n        ),\n        DjangoRouterSchema(\n            name='costcenters',\n            model=models.CompanyCostcenter,\n            get=schemas.response.CompanyCostcenter,\n            create=schemas.request.CompanyCostcenterCreate,\n            update=schemas.request.CompanyCostcenterUpdate,\n        ),\n    ]\n)\n```\n\n## Info for using FastAPI and Django\n\n### ⚠️ Database Connection Leaks\n\nWhen using FastAPI with Django and performing django db operations from within a FastAPI Endpoint, required signals regarding request handling from django are not called.\nThe Django signals `django.core.signals.request_started` and `django.core.signals.request_finished` need to be called prior and after every request (which uses the django orm in it's endpoint), otherwise database connections are leaked undefinedly. Those signals must be called from the **same** thread, in which the orm is used.\n\nThere is a method decorator provided by djfapi in `djfapi.utils.fastapi_django.request_signalling`, which can be applied to any (sync) endpoints. For autogenerated endpoints or manual endpoints decorated with a `DjangoRouterSchema.endpoint`, this is already done.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoltane-eu%2Fdjfapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvoltane-eu%2Fdjfapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoltane-eu%2Fdjfapi/lists"}