vilarneto / pyrtable Goto Github PK
View Code? Open in Web Editor NEWDjango-inspired, Python 3.x library to interface with Airtable
License: MIT License
Django-inspired, Python 3.x library to interface with Airtable
License: MIT License
save method works but I'm getting an error on update:
class Devices(MyBaseRecord):
class Meta:
table_id = 'Devices'
name = StringField('Name')
description = StringField('Description')
class Ips(MyBaseRecord):
class Meta:
table_id = 'Ips'
id = IntegerField('Id')
internal = StringField('Internal')
external = StringField('External')
device = SingleRecordLinkField('Device', linked_class=Devices)
device = Devices(name="pc", description="My pc")
device.save()
ip = Ips(internal="192.168.100.15", external="181.143.142.160", device=device)
ip.save() # It works
ip.internal = "192.168.100.16"
ip.save() # Error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-50-7a5a8299798b> in <module>
----> 1 ip.save()
/usr/local/lib/python3.9/site-packages/pyrtable/record.py in save(self)
214 """
215 from pyrtable.context import get_default_context
--> 216 get_default_context().save(self.__class__, self)
217
218 def encode_to_airtable(self, include_non_dirty_fields=False) -> Dict[str, Any]:
/usr/local/lib/python3.9/site-packages/pyrtable/context/base.py in save(self, record_cls, record)
158 self._create(record_cls, record)
159 else:
--> 160 self._update(record_cls, record)
161
162 def delete_id(self, *,
/usr/local/lib/python3.9/site-packages/pyrtable/context/base.py in _update(self, record_cls, record)
141 if 400 <= response.status_code < 500:
142 error = response.json().get('error', {})
--> 143 error_message = error.get('message', '')
144 error_type = error.get('type', '')
145
AttributeError: 'str' object has no attribute 'get'
Currently BaseRecord.save()
and BaseRecord.delete()
operations operate on single records.
It's interesting to offer an alternative form to these operations that take advantage of the batching capabilities of Airtable API for these operations (currently limited to 10 records per request).
Is there / will there be attachment upload support?
While using pyrtable
in 3.9 the following warning is issued. Python 3.10 was just released and, as it states, this will not work.
python3.9/site-packages/pyrtable/fields/valueset.py:12: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
class ValueSet(collections.MutableSet, collections.Iterable, Generic[T]):
P.S. really enjoy using this in our integration projects with Airtable!
In filterutils.py, the quote value routine. I have apostrophes in the data of one of my string columns in one of my AirTable
tables. The return '"%s"' % re.sub(r'(["\'\\])', lambda ch: '\\' + ch.group(0), value)
is escaping apostrophes.
An example is "augmentin '400'" becomes "augmentin \'400\' before being sent in the filterByFormula querystring field
to AirTable and then MyTable.objects.filter(stringColumnName="augmentin '400'")
yields no results. I don't know if the newer AirTable API automatically escapes apostrophes itself so you don't have to. Looks like we are using pyrtable==0.7.11 from pip freeze.
def quote_value(value) -> str:
import datetime
if isinstance(value, str):
return '"%s"' % re.sub(r'(["\'\\])', lambda ch: '\\' + ch.group(0), value)
if isinstance(value, bool):
return 'TRUE()' if value else 'FALSE()'
if isinstance(value, (int, float)):
return str(value)
if isinstance(value, Enum):
return quote_value(value.value)
if isinstance(value, datetime.datetime):
return format(value, '"%Y-%m-%dT%H:%M:%S.%fZ"')
if isinstance(value, datetime.date):
return format(value, '"%Y-%m-%d"')
raise ValueError(value)
I'm doing this absolutely filthy patch of the code below for the moment to exclude apostrophes from being escaped. When you have some time, perhaps you could create a small Airtable with a single column and put a record in there with an apostrophe in the string to see if your objects.filter function also fails to find the record with an apostrophe in it.
def my_quote_value(value) -> str:
import datetime
import re
from enum import Enum
if isinstance(value, str):
return '"%s"' % re.sub(r'(["\\])', lambda ch: '\\' + ch.group(0), value)
if isinstance(value, bool):
return 'TRUE()' if value else 'FALSE()'
if isinstance(value, (int, float)):
return str(value)
if isinstance(value, Enum):
return my_quote_value(value.value)
if isinstance(value, datetime.datetime):
return format(value, '"%Y-%m-%dT%H:%M:%S.%fZ"')
if isinstance(value, datetime.date):
return format(value, '"%Y-%m-%d"')
raise ValueError(value)
import pyrtable.filterutils
pyrtable.filterutils.quote_value=my_quote_value
Hey, I'm following your example but I'm getting the following error:
266 function = functools.partial(function, base_id=base_id)
267 else:
--> 268 raise ValueError('Cannot use base_id')
269
270 result['Authorization'] = 'Bearer %s' % function()
ValueError: Cannot use base_id
I'm sure the API key and base id are correct because I tried the same using curl
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.