Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 days ago.
The community is reviewing whether to reopen this question as of 5 days ago.
Improve this question
I'm working on a codebase which has a directory containing many pydantic models. (Note: my codebase is not an API.)
How do I go about generating FastAPI-like documentation for pydantic models without an API?
Example codebase layout:
project
│
├───clients
│ ├───models
│ │ ├─── foo.py
│ │ └─── bar.py
│ │
│ └── client_foo.py
│
└───other_stuff
├─── stuff.py
└─── fluff.py
Desired output:
Interactive documentation with the schema of my pydantic models – here is the FastAPI equivelant: https://fastapi.tiangolo.com/tutorial/body/#automatic-docs
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am working on a Python Project and want to call multiple functions from other python files, but I'm having trouble. Can someone please help me?
Each of your Python file can act as a module, that you can import.
for example for numpy you just type 'import numpy' and then you'll be able to use numpy.sin() function.
by default you can only append modules located in sys.path. So What you can do is:
import sys
if not (<folder_with_your_function> in sys.path):
sys.path.append( <folder_with_your_function> )
import <your_function>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Given a project written in C++ with lots of classes (more than a hundred), how to make a rough reimplementation of the code structure?
Edit: as more details are required.
For a project that implements a specific UML Class diagram, I would like to have the same class diagram info generated into Python
Example Source:
my_app
- models
- Company.py (company class)
- Employee.cpp (employee class)
- Laptop.cpp (laptop class)
- Office.cpp (office class)
- common
- utils.cpp (operations and extras classes)
...
Example Output after extraction:
- Company.py
- Employee.py
- Laptop.py
- Office.py
- Operations.py
- Extras.py
Note: As we extract the Class diagram info, generated classes shall contain only the attributes and methods not the implementation
Parse the code with Doxygen and use xml as the output format.
Then use the xml files as input for Langform.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
there is console on under picture
The project is django demo from github, I don't know where modify database username and database password. This is sqlite3.
This is github link: https://github.com/MoreYoungGavin/my_blog
Try delete in your settings.py file the lines
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + [
'django.core.context_processors.request',
]
BOOTSTRAP_ADMIN_SIDEBAR_MENU = True
(as they are only work for django 1.7 and I suppose you have a newer version of Django)
and restart the development server.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
run.py
static/
templates/
tests/
config.py
models.py
I create an instance of my Flask class within run.py, as well as define the views. I am planning on moving the views so they are separate from the run.py file, and just have the run.py file instantiate the Flask class. However, I also have quite a few non-view functions that are called by each of the view functions and implement the application logic.
What is a way to re-organize these view and logic functions to create a good application structure? Should I have a views/ folder with separate view files for each view, including the logic functions that correspond to each of the view functions? Should I group the logic functions together in another, separate folder?
There is some good guidance in the docs. Flask doesn't impose a lot of forced structure but your on the right track for getting in the habit of structuring your projects for your own sanity. This could be entirely left to you how you would like to do this. Probably a lot of opinions out there
What I tend to do is create a structure typical of most python projects. You may want to use an application factory pattern and blueprints.
myapp
/myapp
/home
views.py
/templates
/static
factory.py
core.py
models.py
runserver.py
config.py
Mattupstate has a good blog article on this subject. There is also Fbone. Miguel Grinberg has a chapter in his Flask book dedicated to this too.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am developing a Python App Engine app, where I want to split the content of a source code file Models.py into separate files for each model, but I want to put it all in a folder called Models. The problem is that when I do that, my app can't find the classes anymore. What should I do?
This question is not about MVC but another question with the same title is.
Put an empty __init__.py file in the Models directory.
Then, in your app; presumably one level up, you reference modules in the Models directory like this:
import Models
and do something with it like this:
Models.my_model.MyClassName
You can also use the from keyword like this:
from Models import my_model
and reference like this:
my_model.MyClassName
If you only need one method from a module, you could also do this:
from Models.my_model import my_method_name
my_method_name()
Obligatory link to the documentation.
In response to your comment to Adam's answer, regarding having 10 imports for 10 classes, firstly don't forget that there's no need to have one class per module in Python. Modules should be organised by functionality, so you can group related classes in a single file if that makes sense.
If you still wanted to make all the classes importable in one go, you could import them all in the __init__.py file itself using the from submodule import Class syntax, then just import the containing module - import mainmodule and refer to mainmodule.Class1 etc, or even use from mainmodule import Class1, Class2, Class3 to import the classes directly into your namespace and refer to them directly.
Adam Bernier provides a good technical description of how packages work. A great description of how to arrange and ship a project is described in http://jcalderone.livejournal.com/39794.html