-
Notifications
You must be signed in to change notification settings - Fork 6
Prototype to generate Infrahub Schema from Pydantic models #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## develop #306 +/- ##
============================================
- Coverage 75.74% 33.97% -41.77%
============================================
Files 100 101 +1
Lines 8846 9034 +188
Branches 1732 1693 -39
============================================
- Hits 6700 3069 -3631
- Misses 1670 5688 +4018
+ Partials 476 277 -199
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 74 files with indirect coverage changes 🚀 New features to boost your workflow:
|
36158c8
to
8a8a768
Compare
8a8a768
to
41db077
Compare
Deploying infrahub-sdk-python with
|
Latest commit: |
fded2fd
|
Status: | ✅ Deploy successful! |
Preview URL: | https://37dd3ce0.infrahub-sdk-python.pages.dev |
Branch Preview URL: | https://dga-2020319-prototype-pydant.infrahub-sdk-python.pages.dev |
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
This is an initial Prototype to explore how we could better integrate Pydantic within the SDK
The end goal is to leverage Pydantic to define the schema and to support all CRUD operations, similar to how SQLmodel is working for a Relational Database.
In the current prototype, it's possible to: Define the schema and read objects, the other operations (Create, Update, Delete) aren't available yet
Define Infrahub Schema using Pydantic Models
Below a simple example with 2 models connected together with a relationship (One to Many)
The integration is based on the following principles
NodeModel
orGenericModel
model_config
InfrahubAttributeParam
andInfrahubRelationshipParam
)Field
In the example below, the annotation is used on
cars
to define the identifier for this relationshipQuery data using Pydantic
The main methods to query objects
get
,all
&filters
have been updated to access a Pydantic ModelsIn the example, below the model
Site
that was used to define the schema can also be used to query data.The
client.all()
will automatically format the data returned by the API using the modelSite
, in Pydantic formatCreate / Update objects
This part hasn't been implemented yet but here is an overview of what it could look like following something similar to SQLModel.