0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Workato:Pythonコネクタで利用可能な全モジュールを取得する

Last updated at Posted at 2024-07-25

はじめに

Workatoの標準コネクタで対応できない処理は、Ruby, Python, JavaScriptなどのコネクタを利用することで必要な処理を実装することができます。

各コネクタを利用する際の前提の1つとして、利用可能なモジュールはそのコネクタが提供するモジュールに限られることが挙げられます。言い方を変えると、ユーザーが任意でモジュールを追加することはできません。このため、各コネクタの言語でどのモジュールが利用できるかを知ることが、開発を進めるうえで重要になります。

ここでは、Pythonコネクタで利用可能な全モジュールの取得方法について、手順を記載します。WorkatoのPythonコネクタで利用可能なモジュールは、オフィシャルとしてこちらにまとめられていますが、非常にざっくりとしており全ての対応モジュールが書かれていません。以下の方法で対応しますと、全ての利用可能なモジュールを取得することが可能です。

手順

1.Pythonコネクタをレシピ上へ追加します。

2.追加したPythonコネクタのOutputに result フィールドを追加します。

image.png

3.追加したPythonコネクタのCodeへ以下のコードを入力します

import contextlib
import io

def main(input):
  out_io = io.StringIO()

  with contextlib.redirect_stdout(out_io):
    help("modules")

  out_io.seek(0)
  out = out_io.read()

  tmp = out.replace('Please wait a moment while I gather a list of all available modules...','').replace('Enter any module name to get more help.  Or, type "modules spam" to search','').replace('for modules whose name or summary contain the string "spam".','').replace(" ","\n").split("\n")
  
  result = [val for val in tmp if val != '']

  return {"result": result}

完成したレシピは次の通りとなります。

image.png

実行結果

Test recipeなどでレシピを実行すると、次の通り利用可能な全モジュールを出力結果より確認することができます。

image.png

なお、2024/7/25時点においては、次のモジュールを利用することができます。

OleFileIO_PL
__future__
_abc
_aix_support
_ast
_asyncio
_bisect
_blake2
_bootlocale
_bootsubprocess
_bz2
_cffi_backend
_codecs
_codecs_cn
_codecs_hk
_codecs_iso2022
_codecs_jp
_codecs_kr
_codecs_tw
_collections
_collections_abc
_compat_pickle
_compression
_contextvars
_crypt
_csv
_ctypes
_ctypes_test
_curses
_curses_panel
_datetime
_dbm
_decimal
_distutils_hack
_elementtree
_functools
_gdbm
_hashlib
_heapq
_imp
_io
_json
_locale
_lsprof
_lzma
_markupbase
_md5
_multibytecodec
_multiprocessing
_opcode
_operator
_osx_support
_peg_parser
_pickle
_posixshmem
_posixsubprocess
_py_abc
_pydecimal
_pyio
_queue
_random
_sha1
_sha256
_sha3
_sha512
_signal
_sitebuiltins
_socket
_sqlite3
_sre
_ssl
_stat
_statistics
_string
_strptime
_struct
_symtable
_sysconfigdata__linux_x86_64-linux-gnu
_testbuffer
_testcapi
_testimportmultiple
_testinternalcapi
_testmultiphase
_thread
_threading_local
_tkinter
_tracemalloc
_uuid
_warnings
_weakref
_weakrefset
_xxsubinterpreters
_xxtestfuzz
_zoneinfo
abc
aifc
antigravity
argparse
array
ast
asynchat
asyncio
asyncore
atexit
audioop
base64
bcrypt
bdb
binascii
binhex
bisect
builtins
bz2
cProfile
calendar
certifi
cffi
cgi
cgitb
charset_normalizer
chunk
cmath
cmd
code
codecs
codeop
collections
colorsys
compileall
concurrent
configparser
contextlib
contextvars
copy
copyreg
crypt
cryptography
csv
ctypes
curses
dataclasses
datetime
dateutil
dbm
decimal
difflib
dis
distutils
doctest
email
encodings
ensurepip
enum
errno
et_xmlfile
faulthandler
fcntl
filecmp
fileinput
fnmatch
formatter
fractions
ftplib
functools
gc
genericpath
getopt
getpass
gettext
glob
graphlib
grp
gzip
hashlib
heapq
hmac
html
http
idlelib
idna
imaplib
imghdr
imp
importlib
init
inspect
io
ipaddress
itertools
json
keyword
lib2to3
linecache
locale
logging
lxml
lzma
mailbox
mailcap
marshal
math
mimetypes
mmap
modulefinder
msgpack
msgpack_util
msoffcrypto
multiprocessing
netrc
nis
nntplib
ntpath
nturl2path
numbers
numpy
olefile
opcode
openpyxl
operator
optparse
os
ossaudiodev
pandas
parser
pathlib
pdb
pickle
pickletools
pip
pipes
pkg_resources
pkgutil
platform
plistlib
poplib
posix
posixpath
pprint
profile
pstats
pty
pwd
py_compile
pyclbr
pycparser
pydoc
pydoc_data
pyexpat
pytz
pyxlsb
queue
quopri
random
re
readline
reprlib
requests
resource
rlcompleter
runpy
sched
secrets
select
selectors
setuptools
shelve
shlex
shutil
signal
site
six
smtpd
smtplib
sndhdr
socket
socketserver
spwd
sqlite3
sre_compile
sre_constants
sre_parse
ssl
stat
statistics
string
stringprep
struct
subprocess
sunau
symbol
symtable
sys
sysconfig
syslog
tabnanny
tarfile
telnetlib
tempfile
termios
textwrap
this
threading
time
timeit
tkinter
token
tokenize
trace
traceback
tracemalloc
tty
turtle
turtledemo
types
typing
tzdata
unicodedata
unittest
urllib
urllib3
uu
uuid
venv
warnings
wave
weakref
webbrowser
wsgiref
xdrlib
xlrd
xml
xmlrpc
xxlimited
xxsubtype
zipapp
zipfile
zipimport
zlib
zoneinfo

関連情報

本記事作成にあたり、以下URLに掲載のコードを参考にさせていただきました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?