]> kaliko git repositories - python-musicpdaio.git/blobdiff - doc/source/tutorial/tutorial-01.py
Add Sphinx documentation
[python-musicpdaio.git] / doc / source / tutorial / tutorial-01.py
diff --git a/doc/source/tutorial/tutorial-01.py b/doc/source/tutorial/tutorial-01.py
new file mode 100644 (file)
index 0000000..1ef066c
--- /dev/null
@@ -0,0 +1,30 @@
+import asyncio
+import logging
+
+from mpdaio.client import MPDClient
+
+# Configure loggers
+logging.basicConfig(level=logging.INFO, format='%(levelname)-8s %(message)s')
+logging.getLogger("asyncio").setLevel(logging.WARNING)
+# debug level level will show where defaults settings come from
+log = logging.getLogger('mpdaio.client')
+log.setLevel(logging.DEBUG)
+
+
+async def run():
+    # Use defaults to access MPD server
+    client = MPDClient()
+
+    # Make an initial connection to MPD server
+    # The connection is kept open an reused for later commands
+    await client.ping()
+
+    # Each task gathered here will run with it's own connection
+    await asyncio.gather(...)
+
+    # Closes all connections to MPD server
+    await client.close()
+
+
+if __name__ == '__main__':
+    asyncio.run(run())