Quickbase API client module
Project description
pyqbclient
Simple Quickbase client module
Report Bug
·
Request Feature
Table of Contents
Version 1.0.1
- Fixed a bug with columns in get_data
- Added support for UInt32
- Set a default sort option on queries as paginated queries were returning duplicates without it
About The Project
A module for interacting with the Quickbase API with an emphasis on being easy to use. Everywhere the API calls for record or field IDs I have changed it to work with values or labels. Evolved from simple functions I wrote while getting started with python, has been useful for me, maybe you will find it useful as well.
Getting Started
Requirements
Older versions of below untested, below known to work.
Python (3.8+)
numpy (1.21.4+)
pandas (1.3.4+)
requests (2.26.0+)
lxml (4.6.4+)
Installation
1: Can be installed using pip
pip install pyqbclient
Usage
set_default
Below we supply our realm and token as defaults for all subsequent Client instantiation. Note that both realm_hostname and user_token can be supplied as arguments for the Client directly and that doing so will over-ride any defaults set. I have implemented some logging as well, so we will also configure that
import pyqbclient as pyqbc
import logging
logging.basicConfig(level = logging.INFO)
my_realm = 'example-realm.quickbase.com'
my_token = 'example_token_string'
pyqbc.set_default(realm_hostname=my_realm,user_token=my_token)
Client
Class pyqbclient.Client( table_id, realm_hostname=None, user_token=None, retries=3, dataframe=pd.DataFrame())
Parameters:
table_id: str
The Table ID you want to create a client for
realm_hostname: str
Your quickbase realm hostname
user_token: str
Your quickbase API user token
retries: int
The amount of retries desired for any given request
dataframe: pandas.DataFrame()
The DataFrame associated with the Client, empty DataFrame passed so the editor knows it is a DataFrame.
Below we will instantiate our Client, relying on the defaults we set above
my_table_id = 'example_table_id'
my_table_client = pyqbc.Client(my_table_id)
get_data
pyqbclient.Client.get_data(report=None,columns=None,all_columns=False, overwrite_df=True,return_copy=True,filter_list_dict=None,where=None, **kwargs)
Parameters:
report: str, (optional)
The name of a report you wish to download, e.g "List All"
columns: list, (optional)
A list of field labels corresponding to fields you wish to return, e.g ["Field1","Field2"]
all_columns: bool, (optional)
When True returns all fields as well as any properties of attachment/built in fields (versions, userName etc.)
overwrite_df: bool, (optional)
Overwrites the Client's DataFrame
return_copy: bool, (optional)
Returns a copy of the Client's DataFrame
filter_list_dict: dict, (optional)
Query records based on a list of values. Takes a dictionary set up as below: { 'Field Label': ['Field_value_1','Field_value_2'] }
where: str, (optional)
Filter for queries using modified quickbase query language. Use the field label instead of the field ID, e.g. '{Record_ID#.EX.3}'
**kwargs: * (optional)
Valid kwargs are sortBy and groupBy, consult documentation for utilization
Returns: DataFrame
Below we will get a DataFrame based on the fields and records available in the "List All" report
df = my_table_client.get_data(report='List All')
Note: When called without any arguments returns default fields for all records
For more information on the quickbase query language, please refer to the Documentation
For more information on the query parameters, please refer to the Documentation
post_data
pyqbclient.Client.post_data(external_df=None,step=5000, merge=None, create_if_missing=False, exclude_columns=None, subset=None)
Parameters:
external_df: DataFrame, (optional)
The DataFrame you wish to upload. Omitting uses the client's internal DataFrame
step: int
The amount of records to upload at a time. Quickbase has an upper limit of 10 MB per call, 5k has been pretty safe so far for my use.
merge: str, (optional)
The label of the field you wish to merge on, must be a unique field. Updates where possible, creates where not.
create_if_missing: bool
Create fields in table for any columns in the DataFrame that are not present in the table.
exclude_columns: list
A list of columns in your DataFrame you do not wish to be uploaded
subset: list
A list of columns in your DataFrame you wish to be uploaded while excluding all others (except merge if specified)
Will upload records to the table based on the DataFrame provided. Results are returned in logging.
my_table_client.post_data(external_df=df)
create_fields
pyqbclient.Client.create_fields(field_dict=None,external_df=None, ignore_errors=False, appearsByDefault=True)
Parameters:
field_dict: dict, (optional)
A Dictionary for field creation
external_df: dict, (optional)
Create columns based on a DataFrame
ignore_errors: bool
Ignore errors in creation and continue
appearsByDefault: bool
Whether or not this will be a default field
Will create fields with the given arguments.
field_dict = {
"label": "Field1",
"fieldType": "text"
}
my_table_client.create_fields(field_dict=field_dict)
For more examples, please refer to the Documentation
update_field
pyqbclient.Client.update_field(field_label,field_dict = None,**kwargs)
Parameters:
field_label: str
The label of the field to update
field_dict: dict, (optional)
A dictionary for updating the field
**kwargs: (optional)
Accepts label, noWrap, bold, required, appearsByDefault, findEnabled, unique, fieldHelp, addToForms, properties
Will update fields with the given arguments
my_table_client.update_field("Field1",unique=True)
For more examples, please refer to the Documentation
delete_fields
pyqbclient.Client.delete_fields(field_labels)
Parameters:
field_labels: list
**A list of field labels corresponding to fields **
Will delete the list of supplied fields
my_table_client.delete_fields(["Field1","Field2"])
delete_records
pyqbclient.Client.delete_records(where=None,all_records=False)
Parameters:
where: str, (optional)
Filter for deletion using modified quickbase query language. Use the field label instead of the field ID, e.g. '{Record_ID#.EX.3}'
all_records: bool, (optional)
Delete all records from the table
Will delete indicated records from the table
NOTE: One of where or all_records must be passed as an argument. Former default behaviour was to delete all records without an argument, thought it better to be explicit
my_table_client.delete_records(
where='{Field1.EX."Some Value"}OR{Field1.EX."Some Other Value"}'
)
upload_files
pyqbclient.Client.upload_files(field_label, file_dict, merge_field,try_internal=True)
Parameters:
field_label: str
The label of the field we are uploading the file to
file_dict: dict
A dictionary setup as below: {'Filename with extension': { 'merge_value': 'The value you are merging on', 'file_str': 'Base64 encoded string of your file' } }
merge_field: str
The label of the field we are merging on
try_internal: bool
Whether or not we consult the Client's DataFrame for merge values.
Uploads files to the given file field based on a value in a unique field.
When called, will create a dictionary using the supplied unique field
and built in Record ID# to facilitate the upload. try_internal will attempt
to use the Client's DataFrame before resorting to downloading from the table.
Example usage below
picture_hash = base64.b64encode(picture_IObytes.read()).decode()
file_dict = {
'pic.png': {
'file_str': picture_hash,
'merge_value': 49
}
}
my_table_client.upload_files('Attachment',file_dict,merge_field='Field1')
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE.txt for more information.
Contact
Jeff MacDonald - jeffmacd@protonmail.com
Project Link: https://github.com/jeffmacd/pyqbclient
Acknowledgments
- Some XML functionality derived from https://github.com/pyQuickBase/pyQuickBase
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyqbclient-1.0.1.tar.gz.
File metadata
- Download URL: pyqbclient-1.0.1.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d12c65b6315ef30b416950027dc3b85ee07b018a0cd77210ff40fc900766621d
|
|
| MD5 |
73cc6613767ca37b85439de86f215f7a
|
|
| BLAKE2b-256 |
8132a8356e6fcbaca452a8adc48f0476f2e7719da2e9f2aba837dbb42c5826ca
|
File details
Details for the file pyqbclient-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pyqbclient-1.0.1-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b723ce553881b7cba879861a54b4b20c5c6f28aa56d2aa5fee768587087aa20c
|
|
| MD5 |
31ce9af0e2d005930b6c23d7b1a05390
|
|
| BLAKE2b-256 |
85d9b679c4bc7433358fd9b727d0044fc08779b5b64fb06d28acef992b8dc898
|