<jupyter_start><jupyter_text>---- Data Library for Python----  Content - Pricing - Chain constituentsThis notebook demonstrates how to use the Pricing interface to retrieve the consituents of a Chain instrument :- either as a static snapshot of the current Constituent RICs- or streaming updates for any changes to Constituent RICs  Set the location of the configuration fileFor ease of use, you can set various initialization parameters of the RD Library in the **_refinitiv-data.config.json_** configuration file - as described in the Quick Start -> Sessions example. One config file for the tutorialsAs these tutorial Notebooks are categorised into sub-folders and to avoid the need for multiple config files, we will use the _RD_LIB_CONFIG_PATH_ environment variable to point to a single instance of the config file in the top-level ***Configuration*** folder.Before proceeding, please **ensure you have entered your credentials** into the config file in the ***Configuration*** folder.<jupyter_code>import os
os.environ["RD_LIB_CONFIG_PATH"] = "../../../Configuration"
from refinitiv.data.content import pricing
import refinitiv.data as rd
from pandas import DataFrame
from IPython.display import display, clear_output<jupyter_output><empty_output><jupyter_text>Open the default sessionTo open the default session ensure you have a '*refinitiv-data.config.json*' in the ***Configuration*** directory, populated with your credentials and specified a 'default' session in the config file<jupyter_code>rd.open_session()<jupyter_output><empty_output><jupyter_text>Define and open ChainDefine a streaming price object for the FTSE index.<jupyter_code># define a chain to fetch FTSE constituent RICs
ftse = pricing.chain.Definition(name="0#.FTSE").get_stream()<jupyter_output><empty_output><jupyter_text>Then open method tells the Chain object to subscribe to a stream of the constituent RICs.<jupyter_code>ftse.open()<jupyter_output><empty_output><jupyter_text>Get a list of the current Constituent RICs Once the open method returns, the Chain object is ready to be used. Its internal cache will be updated as and when the list of Consituent changes - which for many Chains is not that often - e.g. the FTSE constituents don't change that often.However, for some chains, the constituents can change more often.<jupyter_code>constituent_list = ftse.constituents
display(constituent_list)<jupyter_output><empty_output><jupyter_text>Other means of accessing the list of constituents  Check if the Stream really is for a chain instrument?<jupyter_code># check is this a chain or not?
print(f"{ftse} is_chain :", ftse.is_chain )<jupyter_output><refinitiv.data.content.pricing.chain.Stream object at 0x28b50586f40 {name='0#.FTSE'}> is_chain : True<jupyter_text>Get constituent in the chain record<jupyter_code># at this point we do snapshot for 1st RIC - as its a streaming request, it may different to the above
first_constituent = ftse.constituents[0]
print(f"{ftse} constituent at index 0 :", first_constituent )
# loop over all constituents in the chain record
for index, constituent in enumerate( ftse.constituents ):
    print(f"{index} = {constituent}")<jupyter_output>0 = AAL.L
1 = ABDN.L
2 = ABF.L
3 = ADML.L
4 = AHT.L
5 = ANTO.L
6 = AUTOA.L
7 = AV.L
8 = AVST.L
9 = AVV.L
10 = AZN.L
11 = BAES.L
12 = BARC.L
13 = BATS.L
14 = BDEV.L
15 = BHPB.L
16 = BKGH.L
17 = BLND.L
18 = BMEB.L
19 = BNZL.L
20 = BP.L
21 = BRBY.L
22 = BT.L
23 = CCH.L
24 = CPG.L
25 = CRDA.L
26 = CRH.L
27 = DCC.L
28 = DGE.L
29 = DPH.L
30 = ECM.L
31 = ENT.L
32 = EVRE.L
33 = EXPN.L
34 = FERG.L
35 = FLTRF.L
36 = FRES.L
37 = GLEN.L
38 = GSK.L
39 = HIK.L
40 = HLMA.L
41 = HRGV.L
42 = HSBA.L
43 = ICAG.L
44 = ICP.L
45 = IHG.L
46 = III.L
47 = IMB.L
48 = INF.L
49 = ITRK.L
50 = ITV.L
51 = JD.L
52 = KGF.L
53 = LAND.L
54 = LGEN.L
55 = LLOY.L
56 = LSEG.L
57 = MGGT.L
58 = MNDI.L
59 = MNG.L
60 = MRON.L
61 = NG.L
62 = NWG.L
63 = NXT.L
64 = OCDO.L
65 = PHNX.L
66 = POLYP.L
67 = PRU.L
68 = PSHP.L
69 = PSN.L
70 = PSON.L
71 = RDSa.L
72 = RDSb.L
73 = REL.L
74 = RIO.L
75 = RKT.L
76 = RMG.L
77 = RMV.L
78 = RR.L
79 = RTO.L
80 = SBRY.L
81 = SDR.L
82 = SGE.L
83 = SGRO.L
84 = SJP.L
85 = SKG.L
86 = SMDS.L
87 = SMIN.L
[...]<jupyter_text>Get the summary links of the chain record<jupyter_code># Chains often have Summary RICs for the chain
summary_links = ftse.summary_links
print(f"summary links of the chain are : {summary_links}")<jupyter_output>summary links of the chain are : ['.FTSE', '.AD.FTSE']<jupyter_text>Close the Streaming Chain instrument<jupyter_code>ftse.close()<jupyter_output><empty_output><jupyter_text>Once close() is called the Chain stops updating its internal cache of Constituents. The get_constituents function can still be called but it will always return the state of the chaing before the close was called.   Additional ParametersYou can control whether to skip summary Links and/or empty constituents - with the optional parameters which default to True.<jupyter_code>ftse = rd.content.pricing.chain.Definition(name="0#.FTSE", 
            skip_summary_links=True, skip_empty=True ).get_stream()<jupyter_output><empty_output><jupyter_text>Snap the Chain constituentsIf you are not planning to use the Chain over an extended period of time and/or just want to snap the current Constituents, you can open it without updates.<jupyter_code>ftse.open(with_updates=False)<jupyter_output><empty_output><jupyter_text>The Library will request the Chain and then close the stream once it has received a response from the server.   You can then use the get_constituents function to access the consituent list as they were at the time of open() call.  Close the session<jupyter_code>rd.close_session()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09052631578947369, 'fraction_numerical': 0.03192982456140351, 'mean_word_length': 4.5673828125, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '376554', 'license': 'Apache-2.0', 'n_tokens_mistral': 2074, 'n_tokens_neox': 1917, 'n_words': 709, 'path': 'Tutorials/2.Content/2.2-Pricing/TUT_2.2.04-Pricing-Chain.ipynb', 'repo_name': 'Refinitiv-API-Samples/Example.DataLibrary.Python', 'size': '5700'}