<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Is the python dropbox api thread safe? in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-the-python-dropbox-api-thread-safe/m-p/723774#M31976</link>
    <description>&lt;P&gt;Hi &lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1714622"&gt;@Carl HR&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I think, you have misinterpreted the topics you have read. The thread safety there is evaluated in regards of ability to transfer session state between threads (something not guaranteed while using default Python requests library). When everything (Dropbox API call needs) is set explicitly, you don't need to care about any loss of state (no state - there is nothing to loss). The underlying library (urllib3,&amp;nbsp; by the way no curl or some fork of libcurl otherwise available too), that carry the actual request, is thread safe. &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@41457EF40051AFF130FDBFE21B496926/emoticons/1f609.png" alt=":winking_face:" title=":winking_face:" /&gt; You have everything you need with one exception - don't share Dropbox client object between threads. The behavior on refresh would be undefined (something easy correctable with redefining '&lt;A title="Checks if access token needs to be refreshed and refreshes if possible" href="https://github.com/dropbox/dropbox-sdk-python/blob/main/dropbox/dropbox_client.py#L360" target="_blank" rel="noopener"&gt;check_and_refresh_access_token&lt;/A&gt;' - enclose the body in mutex).&lt;/P&gt;</description>
    <pubDate>Mon, 23 Oct 2023 23:29:21 GMT</pubDate>
    <dc:creator>Здравко</dc:creator>
    <dc:date>2023-10-23T23:29:21Z</dc:date>
    <item>
      <title>Is the python dropbox api thread safe?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-the-python-dropbox-api-thread-safe/m-p/703491#M31336</link>
      <description>&lt;P&gt;I'm using different dropbox contexts created with &lt;EM&gt;dropbox.Dropbox(...)&lt;/EM&gt;. In my application, I have two or more contexts sharing the same target account (and Console Apps) at a time. Example: contexts &lt;EM&gt;c1, c2&lt;/EM&gt; and &lt;EM&gt;c3&lt;/EM&gt; use the account &lt;A href="mailto:foo@mail.com" target="_blank" rel="noopener"&gt;foo@mail.com&lt;/A&gt; (App Foo) and &lt;EM&gt;c4, c5&lt;/EM&gt; use the account &lt;A href="mailto:asd@mail.com" target="_blank" rel="noopener"&gt;asd@mail.com&lt;/A&gt; (App Asd).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can I use all of them in different threads (one context for a corresponding thread), assuming they will execute in parallel and will work as expected? Is there any need to use mutexes somewhere (in the case which the contexts that share the same account execute at the same time)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried searching about the term "thread" inside the python dropbox docs in case I would find anything related, but found nothing about it. There's no info about the API being thread-safe anywhere on the site, or similar ones.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I can see in the dropbox endpoints v2 page, all operations are be performed by using curl. Should I expect that the python's dropbox api also uses curl internally? Or should I use a python libcurl directly in this case, skipping the dropbox api entirely?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By searching in any python libcurl (such as PycURL, for example), it states that these libraries should be thread safe, which is exactly what I want, but if there's any chance to not have to reinvent the wheel, I would take it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Carl HR.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 17:32:57 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-the-python-dropbox-api-thread-safe/m-p/703491#M31336</guid>
      <dc:creator>Carl HR</dc:creator>
      <dc:date>2023-08-02T17:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: Is the python dropbox api thread safe?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-the-python-dropbox-api-thread-safe/m-p/703500#M31337</link>
      <description>&lt;P&gt;I don't believe we currently have any documented guarantee as to whether or not the Python SDK itself is thread-safe, so I can't make assurances on that, but I'll pass this along as a request to the team for that. I can't promise if or when that might be done though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For reference though, &lt;A href="https://github.com/dropbox/dropbox-sdk-python/blob/487793dff3c5a8a3a76010799dc4803cabdb70f3/dropbox/session.py#L63" target="_blank"&gt;the Dropbox Python SDK uses the requests library&lt;/A&gt; to perform the network requests to the Dropbox API. The Dropbox API servers will automatically take locks on resources as needed, e.g., on "namespaces". Check out &lt;A href="https://developers.dropbox.com/dbx-performance-guide#file-uploads" target="_blank"&gt;this guide for more information on that server-side behavior&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 17:51:34 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-the-python-dropbox-api-thread-safe/m-p/703500#M31337</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2023-08-02T17:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Is the python dropbox api thread safe?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-the-python-dropbox-api-thread-safe/m-p/723738#M31972</link>
      <description>&lt;P&gt;Turns out that this answer is not very easy to answer, as even the requests module don't assure wether their api is thread safe.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Going as far to search on &lt;A href="https://stackoverflow.com/a/20457621/14956120" target="_self"&gt;stackoverflow&lt;/A&gt;&amp;nbsp;and reading the requests module &lt;A href="https://github.com/psf/requests/blob/main/src/requests/api.py#L58" target="_self"&gt;source code&lt;/A&gt;&amp;nbsp;, I found out that:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1.&lt;/STRONG&gt; Sharing a single session instance on multiple threads is not thread-safe. However, apparently using one instance per thread is. So, in order to use this api correctly, we'd theoretically need to create different dropbox sessions per thread, in order to run code with thread safety.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2.&lt;/STRONG&gt; Most of the thread-safety of the requests.sessions module depends on wether the urllib3 module is thread-safe. From current records, it turns out that the v2.0 is thread-safe, as seen on this &lt;A href="https://github.com/psf/requests/issues/2766#issuecomment-1600607248" target="_self"&gt;GitHub&lt;/A&gt; thread, and on the urllib &lt;A href="https://urllib3.readthedocs.io/en/stable/" target="_self"&gt;official docs&lt;/A&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Though imho its best to stick with option #1 as it's more reliable.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2023 19:59:23 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-the-python-dropbox-api-thread-safe/m-p/723738#M31972</guid>
      <dc:creator>Carl HR</dc:creator>
      <dc:date>2023-10-23T19:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: Is the python dropbox api thread safe?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-the-python-dropbox-api-thread-safe/m-p/723774#M31976</link>
      <description>&lt;P&gt;Hi &lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1714622"&gt;@Carl HR&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I think, you have misinterpreted the topics you have read. The thread safety there is evaluated in regards of ability to transfer session state between threads (something not guaranteed while using default Python requests library). When everything (Dropbox API call needs) is set explicitly, you don't need to care about any loss of state (no state - there is nothing to loss). The underlying library (urllib3,&amp;nbsp; by the way no curl or some fork of libcurl otherwise available too), that carry the actual request, is thread safe. &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@41457EF40051AFF130FDBFE21B496926/emoticons/1f609.png" alt=":winking_face:" title=":winking_face:" /&gt; You have everything you need with one exception - don't share Dropbox client object between threads. The behavior on refresh would be undefined (something easy correctable with redefining '&lt;A title="Checks if access token needs to be refreshed and refreshes if possible" href="https://github.com/dropbox/dropbox-sdk-python/blob/main/dropbox/dropbox_client.py#L360" target="_blank" rel="noopener"&gt;check_and_refresh_access_token&lt;/A&gt;' - enclose the body in mutex).&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2023 23:29:21 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-the-python-dropbox-api-thread-safe/m-p/723774#M31976</guid>
      <dc:creator>Здравко</dc:creator>
      <dc:date>2023-10-23T23:29:21Z</dc:date>
    </item>
  </channel>
</rss>

