Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Python Bigquery Connection Using Google BigQuery API Key and InsertQuery?

    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 873
    Answer it

    Hello everyone,

    I need help to insert data into bigquery using python. I am trying to make connection using bigquery API key using this method.

    service= build('bigquery', 'v2', developerKey='XXXXXXXXXXXXXXXXX')
    print service

    I am not able to find the insert method. can anyone please help me to do this work.

    I had also used pandas dataframe to insert. I successfully insert but when I use it in cron on window server it dosesn't works.

     

    I had used this below function for inserting dataframe:

    my_dataframe.to_gbq('fb_raw_data.audience_size', 'XXXXXXXXXXXX', if_exists='replace', private_key='C:\Users\Vikas Chauhan\Desktop\contact\New folder\pCloud Project 1-d06466501680.json')

     

 2 Answer(s)

  • Hi Vikas,
    I think you can check your setup.py file code is similar as like below if yes then you can use..
    from distutils.util import convert_path
    from setuptools import find_packages
    from setuptools import setup
    
    ds = {}
    version_path = convert_path('bigquery/test.py')
    with open(test_path) as test_file:
        exec(version_file.read(), ds)
    
    setup_args = dict(
        name='BigQuery-Python',
        description='test Python client for interacting with Google BigQuery.',
        test=ds['__version__'],
        license='Apache',
        packages=find_packages(),
        include_package_data=True,
        install_requires=[
            'google-api-python-client',
            'httplib2',
            'python-dateutil'
        ],
        author='Tyler Treat',
        author_email='test@gmail.com',
        classifiers=[
            'Development Status ::4 - Production/Stable or not',
            'Environment :: Web Environment',
            'Intended Audience :: Developers',
            'Operating System :: OS Independent',
            'Programming Language :: Python',
        ],
    )
    
    if __name__ == '__main__':
        setup(**setup_args1)
     
  • I think this is use full for you and also please check this link
    https://cloud.google.com/bigquery/create-simple-app-api#bigquery-simple-app-query-python

    query_results = client.run_sync_query("""write here create query;""")
    query_results.test = False
    query_results.run()
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: