You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.1 KiB
HTML

<script>
$(document).ready(function(){
qcms.source_code()
// $('.source-code').each((_index)=>{
// var _code = $('.source-code')[_index]
// var lines = $(_code).text().split('\n')
// $(_code).empty()
// lines.forEach((line)=>{
// line = line.replace(/import/g,'<b>import</b>').replace(/def/g,'<b>def</b>').replace(/\#/g,'<i style="color:darkgray">#').replace(/#.+(\n$)/g,'</i>')
// line = line.replace(/print/g,'<b>print</b>')
// $(_code).append( $('<div></div>').html(line))
// })
// })
})
</script>
<div style="display:grid; grid-template-columns: calc(50% - 4px) 4px 50%; gap:8px;">
<div>
<div class="bold">Collaborative development</div>
<p>
<b>0.</b> In this scenario we assume the registry has been initialized and that an entry has been added (CLI).
<div class="source-code">
# transport registry add --help
<br>$ transport registry add address-db http-auth.json
</div>
</p>
The python code would look like the following :
<div class="source-code" >
<b>import</b> transport
<pre>
#
# We are assuming here that the label books-db is an entry in the registry
dbreader = transport.get.reader(label='address-db') # <i>No database credentials</i>
_df = dbreader.read(sql="SELECT * FROM books where postal_code like '946%' ")
print (_df.head())
</pre>
</div>
<p style="border-top:4px dotted #CAD5E0">
<b>1.</b> Alternatively it is possible to directly use the authentication file dubbed "<b>auth-file</b>".
<div class="source-code" >
<b>import</b> transport
<pre>
#
# We are assuming here that the label books-db is an entry in the registry
dbreader = transport.get.reader(auth_file='/home/me/http-auth.json') # <i>No database credentials</i>
_df = dbreader.read(sql="SELECT * FROM books where postal_code like '946%' ")
print (_df.head())
</pre>
</div>
</p>
</div>
<div style="border-left:4px dotted #CAD5E0;"></div>
<div>
<div class="bold">Non-collaborative development</div>
<p>
In this scenario, we are using connectivity parameters in the code. We do <b>NOT recommend</b> this if the code will be used/shared.
</p>
<div class="source-code">
<b>import</b> transport
<pre>
#
# In this scenario we are loading an SQLite3+ database
url= "https://raw.githubusercontent.com/codeforamerica/ohana-api/master/data/sample-csv/addresses.csv"
_args = {"provider":"http","database"}
dbreader = transport.get.reader(**_args) # <i>No database credentials</i>
_df = dbreader.read(sql="SELECT * FROM books where postal_code like '946%' ")
print (_df.head())
</pre>
</div>
<p style="border-top:4px dotted #CAD5E0">
<div class="bold">Learn more</div>
It is possible to <b>initialize the registry</b>; <b>run ETL</b> from your code as well as from the command line (CLI). We compiled this in notebooks available in our code repository
</p>
</div>
</div>