{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import firebase_admin\n", "from firebase_admin import db, credentials\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cred = credentials.Certificate(\"credentials.json\")\n", "firebase_admin.initialize_app(cred, {\"databaseURL\": \"https://sample-992d1-default-rtdb.firebaseio.com\"})" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "ref = db.reference(\"/\")\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'name': 'tiru'}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ref.get()\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "ref.key" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'tiru'" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db.reference('/name').get()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "db.reference('/').update( {'class':12})" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'class': 12, 'name': 'tiru'}" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ref.get()" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "db.reference('/class').set('college')" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'class': 'college', 'name': 'tiru'}" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ref.get()" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "db.reference('/').update({'mark':0})" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'class': 'college', 'mark': 0, 'name': 'tiru'}" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db.reference('/').get()" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'class': 'college', 'friend': 'sharvesh', 'mark': 0, 'name': 'tiru'}" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db.reference('/').get()" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "ename": "AttributeError", "evalue": "'NoneType' object has no attribute 'get'", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[23], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mdb\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mreference\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m/\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mkey\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m()\n", "\u001b[1;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'get'" ] } ], "source": [ "db.reference('/').key.get()" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "db.reference('/').update({'friend':'sharvesh'})" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "db.reference('/friend').set('sharvesh k')" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'class': 'college', 'friend': 'sharvesh k', 'mark': 0, 'name': 'tiru'}" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db.reference('/').get()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "{sharvesh:{name:{},grade:{}},tiru:{}}" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.6" } }, "nbformat": 4, "nbformat_minor": 2 }