Coder Social home page Coder Social logo

maluforce's Introduction

Description

This module contains an extension of simple-salesforce Salesforce class (https://github.com/simple-salesforce/) and utility functions that help you manage files and reports in large scales.

Reference

This module's main data structre is a "list of dict" e.g. "lod": [{'a':1},{'a':2}], which is the accepted format by salesforce.

Installation

pip install maluforce

For edit mode installation, n parent directory:

git clone [email protected]:stone-payments/maluforce
pip3 install -e maluforce

For global installation:

pip3 install git+https://github.com/stone-payments/maluforce.git

For ubuntu:

python3 -m pip install git+ssh://[email protected]/stone-payments/maluforce.git --user

To install it as a package on your project:

  • clone the git repo
  • delete .git and .gitgnore files
  • install with pipenv install -e maluforce

Usage

Authenticate

from maluforce import *
sf = Maluforce(username='', password='', security_token='', sandbox=False)

Query

Query as usual:

lod_users = sf.query_salesforce('User',"select id from user limit 10")

Query for a list of of e-mails using format:

l_emails = ['[email protected]','[email protected]'] 
soql = "select id, email from user where email in ('{}')".format("','".join(l_emails))
lod_users = sf.query_salesforce('User',soql))

Parsing to a dataframe:

import pandas as pd
df_users = pd.DataFrame(lod_users)

DML

insert

  • don't pass and Id or you will get an error.
lod_users = [{'LastName': 'Poto','Email': '[email protected]'},{'LastName': 'Poto2','Email': '[email protected]'}]

lod_resp = sf_live.lod_to_saleforce('user','insert',lod_users)

delete/ update

  • only required field is the Id

Report Utilities

to_lod

Parses a pandas.DataFrame to a lod. You can specify which columns from the dataframe tou want to mantain, and rename them.

df_permissionset
AssigneeId AssigneeName Id PermissionSetId
00541000004OVfCAAW Leonardo 0Pa1L000007L0flSAC 0PS410000026AhIGAU
00541000004Om8jAAC Oliveira 0Pa1L000007L0fmSAC 0PS410000026AhIGAU
005410000035wnXAAQ Paulo 0Pa1L000007L0fnSAC 0PS410000026AhIGAU
00541000004OvYEAA0 Lucas 0Pa1L000007L0foSAC 0PS410000026AhIGAU
005410000065T1AAAU Brizolla 0Pa1L000007L0fpSAC 0PS410000026AhIGAU
to_lod(df_permissionset,key_map={"AssigneeId","UserId"},drop=True)

results:

[{'UserId': '00541000004OVfCAAW'},
 {'UserId': '00541000004Om8jAAC'},
 {'UserId': '005410000035wnXAAQ'},
 {'UserId': '00541000004OvYEAA0'},
 {'UserId': '005410000065T1AAAU'},
 {'UserId': '00541000004MpidAAC'}]

Other functions

from maluforce import adjust_report,lod_rename,to_lod

adjust_report

Parses a Salesforce response object into a pandas.DataFrame

lod_rename

Renames a lod

Files Utilities

from maluforce import save_lod_files,read_lod_file,read_lod_files

Used for storing large files into small chunks, so that Salesforce's api character limits are respected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.