Comments (6)
Resolved in #288 🙌
from pyairtable.
We use TypedDict to represent record and field dicts that get returned by Airtable. I don't think it's always practical for us to convert those into models, and it would be a significant change for library users whose code expects those objects as dicts. (Maybe in 3.0)
I do think there's a way to make this library work with both v1 and v2 (it involves conditional imports) but I think we can take our time doing it. As you pointed out, Pydantic 2 made a lot of breaking API changes, so I doubt many people are in a hurry to switch.
(FWIW I do have a couple branches in the works which use BaseModel for net new data structures, like comments and webhooks. Will post those soon.)
from pyairtable.
I see.
While the TypedDict
code has not been around for a pyairtable release yet, people do expect something that behaves like a dict
, right?
Would you entertain the idea of returning a subclasses of
class DictBaseModel(BaseModel):
def __getitem__(self, key):
return getattr(self, key)
instead of TypedDict
?
from pyairtable.
I think we can entertain any idea as long as it demonstrates value. Does this change help us add any new features or capabilities to the library?
from pyairtable.
I feel the main advantage is, Pydantic is a lot more popular than TypedDict
, which means that
- Everyone knows how to use it.
- Oher libraries and tools integrate well with it.
Since PyAirtable already depends on Pydantic internally, it would make sense to also use it for the interface.
Pydantic is probably going to be the way forward for ORM. It would be confusing if part of PyAirtable interface is in Pydantic, and another part is in TypedDict.
And now would be a good time for this switch, before the TypedDict implementation hit a release. I think the change would be very straightforward. If you feel like it's worth it, I can implement it.
I have not used TypedDict
before, so I don't know its limitations compared to Pydantic.
from pyairtable.
TypedDict is part of the Python standard library; you can read more about it here.
I don't think it's confusing for parts of the pyAirtable API, like table.all()
, to return dict
, especially when those data structures are more or less "raw" passthroughs of what the Airtable API returns itself. Every Python developer knows how to deal with a dict
and understands their behavior. Far fewer are familiar with Pydantic models and their quirks.
At this point the primary argument for not changing the return type of table.all()
is for backwards compatibility. If we're going to replace that with Pydantic model instances (which implement __getitem__
, maybe) then there's got to be some clear benefit in the form of new library capabilities. If there are specific examples of how this change might make it easier to integrate pyAirtable with other libraries, I'm all for hearing those.
For now I think the scope of this issue should be limited to supporting both Pydantic v1 and v2 (so we can minimize dependency conflicts) or, if that proves impossible, migrating to Pydantic v2 once it's clear that the older version of the library is no longer the dominant dependency (but we're not there yet).
from pyairtable.
Related Issues (20)
- Proposing a different take on ORM solution HOT 3
- Roadmap for future releases HOT 7
- Support `urllib3 >= 2` HOT 1
- For discussion: consider removing `ApiAbstract` HOT 1
- For discussion: adding Pydantic for metadata models HOT 4
- Support for NocoDB HOT 1
- Key error fields with batch_upsert
- version 1.5.0 - pip installs different version of API from what's on Github HOT 6
- batch_upsert does not return createdRecords or updatedRecords HOT 1
- 'Api' object has no attribute 'table' HOT 1
- Suddenly getting AttributeError? HOT 1
- Loading a base with Base() and name overwrites id HOT 2
- Airtable Insert error code 422 HOT 4
- `Api.all()` not present but indicated in `Api` docstring HOT 2
- Webhook delete method HOT 2
- Importing formulas wont work HOT 2
- to_airtable_value() might not be correct for date and datetime values HOT 2
- Add more formulas HOT 2
- Update does not accept return_fields_by_field_id parameter HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyairtable.