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.

Calling datamodel-code-generator programatically

See original GitHub issue

Background Information

I would like to use the datamodel-code-generator in a program which automates the extraction of data-models of an existing API documentation. Unfortunately the API documentation is not in a JSON-format, but a simple Website. So the plan is to parse the Website and create a JSON Schema with the information I gained.

Actual Feature Request

I plan to generate the Pydantic Models with the extracted JSON schema. The question is if it is possible to use datamodel-code-generator programmatically.

# I generate the json schema
json_schema: str = extract_from_website()

# And pass it to the datamodel-code-generator which in turn generates the pydantic_models
pydantic_models: str = generate(json_schema, ...some_args)
               # or whatever fits best

I had a quick look at the code, but the generate function does not look like it is intended to be used that way. So would it be possible to modify it in a way so you can use the library from python and not just as a command line tool?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
HuiiBuhcommented, Dec 27, 2020

Thanks that looks great

2reactions
HuiiBuhcommented, Dec 21, 2020

Thanks for the quick reply. That looks really great and does not feel to much like a workaround.

And thanks for the your lib which really saves me a lot of time

Read more comments on GitHub >

github_iconTop Results From Across the Web

API Client · Issue #40 · koxudaxi/datamodel-code-generator
I would set the first scope is to create code-generator for server-side in the next project. And, a second is to create code-generator...
Read more >
datamodel-code-generator - GitHub Pages
This code generator creates pydantic model from an openapi file and others.
Read more >
Code Generation - pydantic
The datamodel-code-generator project is a library and command-line utility to generate pydantic models from just about any data source, ...
Read more >
Tutorial: Create a more complex data model for an ASP.NET ...
In this tutorial you add more entities and relationships and you customize the data model by specifying formatting, validation, and database ...
Read more >
Generate Pydantic Models from JSON in the browser : r/Python
Full credit for the actual model creation goes to the datamodel-code-generator project!
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