Skip to content

Add multi-file model output#479

Open
PaleNeutron wants to merge 1 commit into
agronholm:masterfrom
PaleNeutron:feature/multi-file-output-pr
Open

Add multi-file model output#479
PaleNeutron wants to merge 1 commit into
agronholm:masterfrom
PaleNeutron:feature/multi-file-output-pr

Conversation

@PaleNeutron
Copy link
Copy Markdown

Closes #88.

This adds a CLI option for writing generated models into a directory, with one Python file per generated model:

  • --output-directory <dir> creates the directory if needed
  • shared declarations are written to base_model.py
  • an empty __init__.py is created
  • each generated model is written to its own .py file

The generator API now also accepts generate(multi_file=True) and returns a mapping of module names to generated source strings. Calling generate() without arguments preserves the existing single-file behavior.

Verification:

  • uv run pytest
  • uv run ruff check .

@coveralls
Copy link
Copy Markdown

coveralls commented Jun 3, 2026

Coverage Status

coverage: 97.802% (-0.04%) from 97.839% — PaleNeutron:feature/multi-file-output-pr into agronholm:master

@sheinbergon
Copy link
Copy Markdown
Collaborator

@PaleNeutron thank you for your contribution. While there has been a long discussion about this request in the original issue, I feel the a file per module maybe a bit of an exaggeration. I would say a file per schema makes more sense, but feel free to counter that idea. @agronholm wdyt?

@PaleNeutron
Copy link
Copy Markdown
Author

@sheinbergon , we subscribe financial data into a database and the provider put about 2000 tables in one schema. Split models by schema can not solve this problem.

BTW, generally schema count is less than 10 and generate each one in a loop is acceptable, no need to create a new option.

Copy link
Copy Markdown
Collaborator

@sheinbergon sheinbergon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One smal change request

Comment thread src/sqlacodegen/generators.py
@sheinbergon
Copy link
Copy Markdown
Collaborator

@sheinbergon , we subscribe financial data into a database and the provider put about 2000 tables in one schema. Split models by schema can not solve this problem.

BTW, generally schema count is less than 10 and generate each one in a loop is acceptable, no need to create a new option.

Alright, Fine by me. Submitted one small change request

@PaleNeutron PaleNeutron force-pushed the feature/multi-file-output-pr branch from 4dede94 to 03464f2 Compare June 3, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output Models to Different Files

3 participants