How To Customize Python Module

One of the greatest things in Python is that it has heaps of cool modules to use. They make programming fun and easy. Here is the example of an amazing salesforce API module.

What makes it even better is that these python modules are easy to customise for your need by editing the source code and recompiling it (if necessary). In this post, I will show you how to customise python modules by using the example of the sharepy module.

Sharepy handles authentication for SharePoint Online/Office365 site and allows you to make API calls. For the further details of the example of sharepoint data ingestion, have a look here.

Sharepy authentication works like this:

import sharepy
s = sharepy.connect("example.sharepoint.com")

For initialisation, the connect method will ask you to input user name and password in the console. To deploy the code in the server, I need to include user name and password when we initialise without typing it in the console.

We want to get sharepy to initialise with user name and password parameters as below:

import sharepy_custom as sharepy
s = sharepy.connect("example.sharepoint.com", , )

Sharepy is well documented and you can check the source code here.

Steps

(1) Download the sharepy module as a zip file from here.

(2) Unzip the file and edit name to “sharepy_custom” in setup.py.

(3) Open session.py in the sharepy folder.

(4) In line 17 and 18, add username and password in the method argument and class construction.

(5) Add username and password in the class constructor as below. Delete input in line 56 and 72.

(6) Go to the sharepy folder and run the command below.

python setup.py install

This will create a folder in your python site-packages library folder. In the screenshot, sharepy and sharepy-1.1.3.dist-info were created py pip install sharepy command. They contain the native module. Running setup.py install created the folder sharepy_custom-1.1.3-py3.4.egg, which has compiled modules with the custom code.

(7) Go into the the folder sharepy_custom-1.1.3-py3.4.egg and change the sharepy folder name to sharepy_custom. This name will be used to import the module.

Now we can import the customised module and use it as we planned!

import sharepy_custom as sharepy
s = sharepy.connect("example.sharepoint.com", , )

Go check out how this customised sharepy is used to ingest data from Sharepoint!

Git
How to specify which Node version to use in Github Actions

When you want to specify which Node version to use in your Github Actions, you can use actions/setup-node@v2. The alternative way is to use a node container. When you try to use a publicly available node container like runs-on: node:alpine-xx, the pipeline gets stuck in a queue. runs-on is not …

AWS
Using semantic-release with AWS CodePipeline and CodeBuild

Here is the usual pattern of getting the source from a git repository in AWS CodePipeline. In the pipeline, we use AWS CodeStart to connect to a repo and get the source. Then, we pass it to the other stages, like deploy or publish. For some unknown reasons, CodePipeline downloads …

DBA
mysqldump Error: Unknown table ‘COLUMN_STATISTICS’ in information_schema (1109)

mysqldump 8 enabled a new flag called columm-statistics by default. When you have MySQL client above 8 and try to run mysqldump on older MySQL versions, you will get the error below. mysqldump: Couldn’t execute ‘SELECT COLUMN_NAME, JSON_EXTRACT(HISTOGRAM ‘$”number-of-buckets-specified”‘) FROM information_schema.COLUMN_STATISTICS WHERE SCHEMA_NAME = ‘myschema’ AND TABLE_NAME = ‘craue_config_setting’;’: Unknown …