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.

Generation of models from the Python dictionary

See original GitHub issue

Thank you for the nice package. It is possible to generate models from dict python objects

At the input, I have a python file in which a variable is declared and a dictionary is passed to it. At the output, you need to get a file with the model name as a variable.

The path from the dictionary to the json schema and then to the model is complex. Has an extra step.

Example.

input:

example_variable = {"test_field": "test_value", "test_field2" : 123}

output:

class ExampleVariable(BaseModel):
    "test_field": str
    "test_field2" : int

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
DjaPycommented, Jan 24, 2021

Excellent. Thank you

0reactions
benlawrauscommented, Dec 4, 2021

Is it possible to turn the above output to

class Model(BaseModel):
    test_field: str = 'test_value'
    test_field2: int = 123
    test_fields3: List[int] = [1,2,3]

Thanks for your time!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generate pydantic model from a dict - python - Stack Overflow
You can use MyModel.parse_obj(my_dict) to generate a model from a dictionary. According to the documentation –.
Read more >
Python Dictionary - GeeksforGeeks
In Python, a dictionary can be created by placing a sequence of elements within curly {} braces, separated by 'comma'. Dictionary holds pairs...
Read more >
Dictionaries in Python - Real Python
Here's what you'll learn in this tutorial: You'll cover the basic characteristics of Python dictionaries and learn how to access and manage dictionary...
Read more >
Create a Dictionary in Python – Python Dict Methods
In this article, you will learn the basics of dictionaries in Python. You will learn how to create dictionaries, access the elements inside ......
Read more >
Generating Sentences with n-grams using Python - YouTube
Generating Sentences with n-grams using Python ... And it shows an interesting way to use Python dictionaries and lists. … Show more.
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