question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to individual run file beside main.py in FASTAPI platform?

See original GitHub issue

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google “How to X in FastAPI” and didn’t find any information.
  • I already read and followed all the tutorial in the docs and didn’t find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

in db/database.py

from elasticsearch import Elasticsearch
from dataclasses import dataclass
from core.config import Settings
# from metering_api_gateway.core.config import Settings

Description

How can i individual test/run a python file beside main.py in FASTAPI framework?

Operating System

Linux

Operating System Details

I have similar question related to following

FastAPI Version

0.82

Python Version

3.8

Additional Context

Screenshot from 2022-09-06 13-48-07

How can i indiviudual test a file in FASTAPI framework? i run by poetry run python3 db/database.py it shows error “File “db/database.py”, line 3, in <module> from core.config import Settings ModuleNotFoundError: No module named ‘core’”

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
iudeencommented, Sep 8, 2022

You should run from project root, right? i.e, your imports are relative to project root. And it is same for all python applications (or packages).

Edit: typo - project root

0reactions
github-actions[bot]commented, Dec 1, 2022

Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bigger Applications - Multiple Files - FastAPI
It contains an app/main.py file. As it is inside a Python package (a directory with a file __init__.py ), it is a "module"...
Read more >
Developing and Testing an Asynchronous API with FastAPI ...
Start by creating a folder to hold your project called "fastapi-crud". Then, add a docker-compose.yml file and a "src" folder to the project ......
Read more >
Python & FastAPI Tutorial: Create an ai microservice to extract ...
Learn how to deploy an AI microservice REST API endpoint using FastAPI, pytesseract, Docker, & DigitalOcean App Platform.
Read more >
How to use PostgreSQL database in FastAPI - Educative.io
FastAPI is a Python web framework specially for building APIs. In this article, we will be looking into PostgreSQL with Django.
Read more >
Build a URL Shortener With FastAPI and Python
Create a REST API with FastAPI; Run a development web server with ... Create a file named main.py in the shortener_app/ folder and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found