<jupyter_start><jupyter_text>Using `pymldb` TutorialInteractions with MLDB occurs via a [REST API](../../../../docbuiltin/WorkingWithRest.md.html). Interacting with a REST API over HTTP from a Notebook interface can be a little bit laborious if you're using a general-purpose Python library like [`requests`](http://docs.python-requests.org/en/latest/) directly, so MLDB comes with a Python library called [`pymldb`](https://github.com/datacratic/pymldb) to ease the pain. ConnectionsThe [`pymldb` library](https://github.com/datacratic/pymldb) includes a class called `Connection`. The recommended usage pattern is shown here:<jupyter_code>from pymldb import Connection
mldb = Connection("http://localhost")<jupyter_output><empty_output><jupyter_text>Accessing the REST APIOnce you have a connection object, you can easily make calls to the [REST API](../../../../docbuiltin/WorkingWithRest.md.html):<jupyter_code>mldb.get("/v1/types")
#keyword arguments to get() are appended to the GET query string

mldb.get("/v1/types", x="y")
#dictionaries arguments to put() and post() are sent as JSON via PUT or POST

mldb.put("/v1/datasets/sample", {"type": "sparse.mutable"} )<jupyter_output><empty_output><jupyter_text>Here we create a dataset and insert two rows of two columns into it:<jupyter_code>mldb.put( "/v1/datasets/demo",      {"type":"sparse.mutable"})
mldb.post("/v1/datasets/demo/rows", {"rowName": "first", "columns":[["a",1,0],["b",2,0]]})
mldb.post("/v1/datasets/demo/rows", {"rowName": "second", "columns":[["a",3,0],["b",4,0]]})
mldb.post("/v1/datasets/demo/commit")<jupyter_output><empty_output><jupyter_text>------ SQL QueriesNow that we have a dataset, we can use the `query()` method on the connection to run an [SQL query](../../../../doc/builtin/sql/Sql.md.html) and get the results back as a Pandas DataFrame:<jupyter_code>df = mldb.query("select * from demo")
print type(df)
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16390041493775934, 'fraction_numerical': 0.007780082987551867, 'mean_word_length': 5.494949494949495, 'pattern_counts': {'":': 6, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '296651', 'license': 'Apache-2.0', 'n_tokens_mistral': 654, 'n_tokens_neox': 643, 'n_words': 178, 'path': 'container_files/tutorials/Using pymldb Tutorial.ipynb', 'repo_name': 'kstepanmpmg/mldb', 'size': '1928'}