jupyter-client

https://www.cnblogs.com/wuyongqiang/p/8040225.html  jupyter架构

https://jupyter-client.readthedocs.io/en/latest/api/client.html   jupyter_client说明

https://jupyter-client.readthedocs.io/en/latest/api/manager.html

get_all_specs()

jupyter_client.KernelManager

start_kernel

 

ac = km.client()

c = “print(333)”

ac.excute(code=c)

ac.get_shell_msg()

 

bl2.execute(“import json\ns = {‘sdf’:[2,3,4]}\nss = s.update({‘s’:33})\ns”)
‘e2ee6dc7-b92af4c4bcf254731afe6d97’

bl2.get_shell_msg(‘e2ee6dc7-b92af4c4bcf254731afe6d97’)
{‘header’: {‘version’: ‘5.3’, ‘date’: datetime.datetime(2020, 7, 28, 1, 58, 50, 986394, tzinfo=tzutc()), ‘session’: ‘a12ec4bb-8a410f1c212a8dc51be750ec’, ‘username’: ‘root’, ‘msg_type’: ‘execute_reply’, ‘msg_id’: ‘acf6674a-ef66fc3bd4a88990eca6edd7’}, ‘msg_id’: ‘acf6674a-ef66fc3bd4a88990eca6edd7’, ‘msg_type’: ‘execute_reply’, ‘parent_header’: {‘version’: ‘5.3’, ‘date’: datetime.datetime(2020, 7, 28, 1, 58, 50, 975867, tzinfo=tzutc()), ‘session’: ‘fbaa2347-27715fd0dfca10dc217355e9’, ‘username’: ‘root’, ‘msg_type’: ‘execute_request’, ‘msg_id’: ‘e2ee6dc7-b92af4c4bcf254731afe6d97’}, ‘metadata’: {‘started’: ‘2020-07-28T01:58:50.978667Z’, ‘dependencies_met’: True, ‘engine’: ‘aefc399f-0a1e-4aa2-a243-f086b59d6ea6’, ‘status’: ‘ok’}, ‘content’: {‘status’: ‘ok’, ‘execution_count’: 3, ‘user_expressions’: {}, ‘payload’: []}, ‘buffers’: []}

bl2.execute_interactive(“import json\ns = {‘sdf’:[2,3,4]}\nss = s.update({‘s’:33})\ns”)
{‘sdf’: [2, 3, 4], ‘s’: 33}{‘header’: {‘version’: ‘5.3’, ‘date’: datetime.datetime(2020, 7, 28, 2, 1, 46, 740526, tzinfo=tzutc()), ‘session’: ‘a12ec4bb-8a410f1c212a8dc51be750ec’, ‘username’: ‘root’, ‘msg_type’: ‘execute_reply’, ‘msg_id’: ‘b1641682-3e884c6272ce8c4c78038da0’}, ‘msg_id’: ‘b1641682-3e884c6272ce8c4c78038da0’, ‘msg_type’: ‘execute_reply’, ‘parent_header’:{‘version’: ‘5.3’, ‘date’: datetime.datetime(2020, 7, 28, 2, 1, 46, 731217, tzinfo=tzutc()), ‘session’: ‘fbaa2347-27715fd0dfca10dc217355e9’, ‘username’: ‘root’, ‘msg_type’: ‘execute_request’, ‘msg_id’: ‘c2a1165e-2786b21449979ee097a58c0f’}, ‘metadata’: {‘started’: ‘2020-07-28T02:01:46.733713Z’, ‘dependencies_met’: True, ‘engine’: ‘aefc399f-0a1e-4aa2-a243-f086b59d6ea6’, ‘status’: ‘ok’}, ‘content’: {‘status’: ‘ok’, ‘execution_count’: 4, ‘user_expressions’: {}, ‘payload’: []}, ‘buffers’: []}

import zmq
>>> poller = zmq.Poller()
>>> iopub_socket = bl2.iopub_channel.socket
>>> poller.register(iopub_socket, zmq.POLLIN)
>>> stdin_socket = bl2.stdin_channel.socket
>>> poller.register(stdin_socket, zmq.POLLIN)
>>> events = dict(poller.poll(timeout_ms))

 

 

>>> import jupyter_client
>>> mk=jupyter_client.MultiKernelManager()
>>> kid=mk.start_kernel(‘python3’)
>>> kid
‘3c33a4a9-77e8-4b3a-9ba1-2e7bdee4a53e’
>>> kerid=mk.get_kernel(kid)
>>> kerid.is_alive()
True
>>> bl=kerid.client()
>>> bl.start_channels(shell=False, iopub=True, stdin=False, hb=True, control=False)
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
TypeError: start_channels() got an unexpected keyword argument ‘control’
>>> bl.start_channels(shell=False, iopub=True, stdin=False, hb=True)
>>> bl.execute(‘3333333’)
‘ce8b0d2e-40e944a7f24f9eda8453cfdd’
>>> import zmq
>>> poller = zmq.Poller()
>>> iopub_socket = bl.iopub_channel.socket
>>> poller.register(iopub_socket, zmq.POLLIN)
>>> events = dict(poller.poll(2000))
>>> events
{<zmq.sugar.socket.Socket object at 0x7f0cc8d35048>: 1}
>>>
>>> msg = bl.iopub_channel.get_msg(timeout=0)
>>> msg
{‘header’: {‘version’: ‘5.3’, ‘date’: datetime.datetime(2020, 7, 28, 6, 31, 55, 366827, tzinfo=tzutc()), ‘session’: ‘b96a59fb-b10b374d83a815cfedef0b9b’, ‘username’: ‘root’, ‘msg_type’: ‘status’, ‘msg_id’: ’62f7bec3-90d1bf9e294f41181663124c’}, ‘msg_id’: ’62f7bec3-90d1bf9e294f41181663124c’, ‘msg_type’: ‘status’, ‘parent_header’: {‘version’: ‘5.3’, ‘date’: datetime.datetime(2020, 7, 28, 6, 31, 55, 364191, tzinfo=tzutc()), ‘session’: ‘8d7e893a-414d747237ce8177fd51b7a4’, ‘username’: ‘root’, ‘msg_type’: ‘execute_request’, ‘msg_id’: ‘ce8b0d2e-40e944a7f24f9eda8453cfdd’}, ‘metadata’: {}, ‘content’: {‘execution_state’: ‘busy’}, ‘buffers’: []}
>>> msg[‘parent_header’].get(‘msg_id’)
‘ce8b0d2e-40e944a7f24f9eda8453cfdd’
>>> msg[‘header’][‘msg_type’]
‘status’
>>> msg = bl.iopub_channel.get_msg(timeout=0)
>>> msg
{‘header’: {‘version’: ‘5.3’, ‘date’: datetime.datetime(2020, 7, 28, 6, 31, 55, 367531, tzinfo=tzutc()), ‘session’: ‘b96a59fb-b10b374d83a815cfedef0b9b’, ‘username’: ‘root’, ‘msg_type’: ‘execute_input’, ‘msg_id’: ‘b6287123-cb779ceba1778a1f4b2ee010’}, ‘msg_id’: ‘b6287123-cb779ceba1778a1f4b2ee010’, ‘msg_type’: ‘execute_input’, ‘parent_header’: {‘version’: ‘5.3’, ‘date’: datetime.datetime(2020, 7, 28, 6, 31, 55, 364191, tzinfo=tzutc()), ‘session’: ‘8d7e893a-414d747237ce8177fd51b7a4’, ‘username’: ‘root’, ‘msg_type’: ‘execute_request’, ‘msg_id’: ‘ce8b0d2e-40e944a7f24f9eda8453cfdd’}, ‘metadata’: {}, ‘content’: {‘code’: ‘3333333’, ‘execution_count’: 1}, ‘buffers’: []}
>>>
>>> msg[‘header’][‘msg_type’]
‘execute_input’
>>> msg = bl.iopub_channel.get_msg(timeout=0)
>>> msg[‘header’][‘msg_type’]
‘execute_result’
>>> msg
{‘header’: {‘version’: ‘5.3’, ‘date’: datetime.datetime(2020, 7, 28, 6, 31, 55, 369924, tzinfo=tzutc()), ‘session’: ‘b96a59fb-b10b374d83a815cfedef0b9b’, ‘username’: ‘root’, ‘msg_type’: ‘execute_result’, ‘msg_id’: ’51f87029-4940b7d69e1be36963c5ac02′}, ‘msg_id’: ’51f87029-4940b7d69e1be36963c5ac02′, ‘msg_type’: ‘execute_result’, ‘parent_header’: {‘version’: ‘5.3’, ‘date’: datetime.datetime(2020, 7, 28, 6, 31, 55, 364191, tzinfo=tzutc()), ‘session’: ‘8d7e893a-414d747237ce8177fd51b7a4’, ‘username’: ‘root’, ‘msg_type’: ‘execute_request’, ‘msg_id’: ‘ce8b0d2e-40e944a7f24f9eda8453cfdd’}, ‘metadata’: {}, ‘content’: {‘data’: {‘text/plain’: ‘3333333’}, ‘metadata’: {}, ‘execution_count’: 1}, ‘buffers’: []}

 

 

neo4j例子

match (a)-[r]->(b)
where type(r) in [‘sHAS’,’sHAS_dans’,’sHas_dan’,’sHAS_tech_t’,’sHAS_tech_ts’,’sHAS_tech’]
return id(a),a.id,replace(a.name,”\n”,””),r.name,id(b),b.id,replace(b.name,”\n”,”-“),labels(b)

match (a:Technology_info),(b:S_Technology_s),(c:Enterprise_s)
where a.disable=’0′ and a.gongyimingcheng=b.name and b.qiyemingcheng=c.qiyemingcheng
merge (c)-[r:sHAS_tech{name:a.gongyimingcheng}]->(a)
return c,a,r.name

MATCH (a:Enterprise_s),(b:S_Dangerous),(c:Dangerou)
where a.qiyemingcheng=b.qiyemingcheng and (b.chanpinzuidachuliang <>” or b.chanpinzuidachuliang1 <> ”) and b.disable <> ‘1’ and b.zhongwenming = c.name
merge (a)-[r:sHAS_dans{name:”重点危化品存储”}]->(c)
return a,r,c.name

MATCH (a:Enterprise_s),(b:S_Dangerous),(c:Dangerou)
where a.qiyemingcheng=b.qiyemingcheng and (b.chanpinshengchannen1 <>” or b.chanpinshengchanneng <> ”) and b.disable <> ‘1’ and b.zhongwenming = c.name
merge (a)-[r:sHAS_dans{name:”重点危化品生产”}]->(c)
return a,r,c.name

MATCH (a:Enterprise_s),(b:S_Dangerous),(c:Dangerou)
where a.qiyemingcheng=b.qiyemingcheng and (b.nianshejishiyonglian <>” or b.nianshejishiyongqiti <> ”) and b.disable <> ‘1’ and b.zhongwenming = c.name
merge (a)-[r:sHAS_dans{name:”重点危化品使用”}]->(c)
return a,r,c.name

match (a:Dangerous_s),(b:Dangerou),(c:Enterprise_s)
WHERE a.zhongwenming=b.name and a.qiyemingcheng=c.qiyemingcheng and a.weihuapinshejihuanji =~ “.*使用.*”
with c,b
merge (c)-[r:sHas_dan{name:”危化品使用”}]->(b)
return r
match (a:Park_s{id:”18″})-[r]->(b)-[r2]->(c)
where right(r2.name,2) <> “风险”
return a,b,c,r,r2

match (c:S_Technology_s),(a:Dangerou),(b:Technology_info)
where  c.zhongjianchanpin = a.name  and c.name=b.gongyimingcheng and b.disable <> ‘1’
with b,a
match (b),(a),(d:Dangerou_category)
where a.name = d.pinming and d.disable <> ‘1’ and d.huaxuepinleixing=”重点监管危险化学品”
merge (b)-[r:sHAS_tech_ts{name:’重点危化品中间产品’}]->(a)
return b,a

neo4j

MATCH (n:Test) RETURN distinct keys(n)   查看哪些属性

https://www.cnblogs.com/jstarseven/p/9546602.html  例子

https://www.it1352.com/1674148.html 模糊查询

https://blog.csdn.net/weixin_40739969/article/details/101781409  字符串函数
https://www.w3cschool.cn/neo4j/neo4j_cql_union.html 手册

https://www.cnblogs.com/sea520/p/11940400.html   关系复杂查询

https://www.jianshu.com/p/8b9b49e9e3cf   详细用法

https://www.jianshu.com/p/8b9b49e9e3cf neo4j的一些特别用法