Flask Webcast #3: Circular Dependencies

In this live webcast I explain how to prevent circular dependency errors in Python. Most of this presentation is a live coding session in which I refactor a single-file Flask application into a fully fleshed out structure with multiple packages and modules, demonstrating how I completely avoid circular dependencies.


  • #1 Haris said 2019-02-26T12:27:51Z

    How are you testing this with tox flake8? Can you explain it a little when and how it is used for testing dependancies, and whether I can use it on my Windows as well? Thanks

  • #2 Miguel Grinberg said 2019-02-26T21:13:30Z

    @Haris: I don't have a copy of the configuration that I used in this video, but I don't use it for anything specifically related to circular dependencies, just to make sure that after I do some refactoring work there are no obvious mistakes. And yes, this works on Windows as well.

  • #3 margrami said 2019-10-25T10:14:27Z

    Hola Miguel, Congratulations, your blog is really a reference about Flask. Thank you for sharing.

  • #4 Lucas Baião Pires said 2020-07-13T19:05:23Z

    In my opinion, this still is circular dependency. The program works just because you are making the imports in different lines, but this should not happen. There should be a more elegant solution for this. Other languages, such as C#, TypeScript, Java, etc, do not present such problems, and do not resort to such poor solutions. I just hate that I cannot find a work around this!

  • #5 Miguel Grinberg said 2020-07-14T14:14:17Z

    @Lucas: the workaround is to organize your files so that circular references aren't necessary. It is possible, but a lot more work.

Leave a Comment