Lore Duran

Lore Duran

1583581320

Python Firebase SDK Integration With Real Time Database

In this Python Firebase article iam going to show you Firebase SDK Integration with Realtime Database.

With the Admin SDK, you can read and write Realtime Database data with full admin privileges, or with finer-grained limited privileges. also Admin SDK lets you interact with Firebase from privileged environments to perform actions like:

  • Read and write Realtime Database data with full admin privileges.
  • Programmatically send Firebase Cloud Messaging messages using a simple, alternative approach to the Firebase Cloud Messaging server protocols.
  • Generate and verify Firebase auth tokens.
  • Access Google Cloud Platform resources like Cloud Storage buckets and Cloud Firestore databases associated with your Firebase projects.
  • Create your own simplified admin console to do things like look up user data or change a user’s email address for authentication.

You can check the complete video tutorial for this article at the end.

Before this i had an article on Python Firebase using wrapper libraries.

1: Python Firebase Full Course For Beginners

You can check Firebase Admin SDK features that are available for different programming languages in this link.

Firebase Admin SDK Features

Setup Firebase Project & Service Account

To use the Firebase Admin SDKs, you’ll need the following:

  • A Firebase project
  • A service account to communicate with Firebase
  • A configuration file with your service account’s credentials

OK so after creation of your project in Firebase Console, you need to enable Realtime Database in your project.

after that for integration of Firebase SDK you need to install the SDK for the language of your choice. because we are using python, so we do the process for python programming language. you can easily install Firebase Admin SDK with pip like this.

pip install firebase-admin

To authenticate a service account and authorize it to access Firebase services, you must generate a private key file in JSON format.

  1. In the Firebase console, open Settings > Service Accounts.
  2. Click Generate New Private Key, then confirm by clicking Generate Key.
  3. Securely store the JSON file containing the key.

and add that json file to your working directory.

Python Firebase SDK

**Admin SDK Integration **

Before you can access the Firebase Realtime Database from a server using the Firebase Admin SDK, you must authenticate your server with Firebase. When you authenticate a server, rather than sign in with a user account’s credentials as you would in a client app.

When you initialize the Firebase Admin SDK with the credentials for a service account with the Editor role on your Firebase project, that instance has complete read and write access to your project’s Realtime Database.

import firebase_admin
from firebase_admin import credentials
from firebase_admin import db



# Fetch the service account key JSON file contents
cred = credentials.Certificate('firebase-sdk.json')

# Initialize the app with a service account, granting admin privileges
firebase_admin.initialize_app(cred, {
    'databaseURL': 'https://testpro-72243.firebaseio.com/'
})

So in the above code this is for fetching the service account key json file. and make that you have downloaded the key and added that to your working directory.

cred = credentials.Certificate('firebase-sdk.json')

Because we are working with Realtime Database, so after enabling Reatime Database you need to add the url of the database.

firebase_admin.initialize_app(cred, {
    'databaseURL': 'https://url of the realtime database/'
})

Now the setup is completed we need to add some data to our realtime database using this code.

ref = db.reference('/')
ref.set({
        'Employee':
            {
                'emp1': {
                    'name': 'Parwiz',
                    'lname': "Forogh",
                    'age': 24,

                },
                'emp2': {
                    'name': 'John',
                    'lname': 'Doe',
                    'age': 20,

                }

            }
        })

You can use set for adding data to your realtime database

For updating you need to add this code

ref = db.reference('Employee')
box_ref = ref.child('emp1')
box_ref.update({
    'name': 'updated name'
})

If you want to work with multiple path update, you can use this code.

ref = db.reference('Employee')
ref.update({
    'emp1/lname': 'updated lname',
    'emp2/lname': 'updated lname'
})

There is also another way that you can add data, using this way you can create key for your data, in the first way that we have used for adding data, there is no key for our data.

ref = db.reference('Employee2')
# Generate a reference and add some data using push()
emp_ref = ref.push({
    'name': 'Bob',
    'lname': "Logan",
    'age': 26

})

# Get the unique key generated 
emp_key = emp_ref.key
print(emp_key)

You can retrieve the data easily using this code.

ref = db.reference('Employee')
print(ref.get())

This is the complete code for this article

import firebase_admin
from firebase_admin import credentials
from firebase_admin import db



# Fetch the service account key JSON file
cred = credentials.Certificate('firebase-sdk.json')

# Initialize the app with a service account
firebase_admin.initialize_app(cred, {
    'databaseURL': 'https://Firebase Realtime Database URL/'
})



ref = db.reference('/')
ref.set({
        'Employee':
            {
                'emp1': {
                    'name': 'Parwiz',
                    'lname': "Forogh",
                    'age': 24,

                },
                'emp2': {
                    'name': 'John',
                    'lname': 'Doe',
                    'age': 20,

                }

            }
        })



'''
#updating data
ref = db.reference('Employee')
box_ref = ref.child('emp1')
box_ref.update({
    'name': 'updated name'
})

'''

#working with mullti path update

'''
ref = db.reference('Employee')
ref.update({
    'emp1/lname': 'updated lname',
    'emp2/lname': 'updated lname'
})
'''

#adding data in second way you can create the key

'''
ref = db.reference('Employee2')
# Generate a reference to a location 
emp_ref = ref.push({
    'name': 'Bob',
    'lname': "Logan",
    'age': 26

})

# Get the unique key generated
emp_key = emp_ref.key
print(emp_key)

'''


#retreiving data
'''
ref = db.reference('Employee')
print(ref.get())
'''

#python #firebase #databases

What is GEEK

Buddha Community

Python Firebase SDK Integration With Real Time Database
Ray  Patel

Ray Patel

1619510796

Lambda, Map, Filter functions in python

Welcome to my Blog, In this article, we will learn python lambda function, Map function, and filter function.

Lambda function in python: Lambda is a one line anonymous function and lambda takes any number of arguments but can only have one expression and python lambda syntax is

Syntax: x = lambda arguments : expression

Now i will show you some python lambda function examples:

#python #anonymous function python #filter function in python #lambda #lambda python 3 #map python #python filter #python filter lambda #python lambda #python lambda examples #python map

Create database into firebase

https://youtu.be/u3F3GCdBu08

#firebase #firebase database #c# with firebase #c# with firebase database #c# with firebase tutorials #asp.net with firebase database

What is firebase,firebase bangla tutorial.

https://youtu.be/8BnVKuf1E5M

#firebase #firebase database #c# with firebase #c# with firebase tutorials #c# with firebase database #asp.net with firebase database

Shardul Bhatt

Shardul Bhatt

1626775355

Why use Python for Software Development

No programming language is pretty much as diverse as Python. It enables building cutting edge applications effortlessly. Developers are as yet investigating the full capability of end-to-end Python development services in various areas. 

By areas, we mean FinTech, HealthTech, InsureTech, Cybersecurity, and that's just the beginning. These are New Economy areas, and Python has the ability to serve every one of them. The vast majority of them require massive computational abilities. Python's code is dynamic and powerful - equipped for taking care of the heavy traffic and substantial algorithmic capacities. 

Programming advancement is multidimensional today. Endeavor programming requires an intelligent application with AI and ML capacities. Shopper based applications require information examination to convey a superior client experience. Netflix, Trello, and Amazon are genuine instances of such applications. Python assists with building them effortlessly. 

5 Reasons to Utilize Python for Programming Web Apps 

Python can do such numerous things that developers can't discover enough reasons to admire it. Python application development isn't restricted to web and enterprise applications. It is exceptionally adaptable and superb for a wide range of uses.

Robust frameworks 

Python is known for its tools and frameworks. There's a structure for everything. Django is helpful for building web applications, venture applications, logical applications, and mathematical processing. Flask is another web improvement framework with no conditions. 

Web2Py, CherryPy, and Falcon offer incredible capabilities to customize Python development services. A large portion of them are open-source frameworks that allow quick turn of events. 

Simple to read and compose 

Python has an improved sentence structure - one that is like the English language. New engineers for Python can undoubtedly understand where they stand in the development process. The simplicity of composing allows quick application building. 

The motivation behind building Python, as said by its maker Guido Van Rossum, was to empower even beginner engineers to comprehend the programming language. The simple coding likewise permits developers to roll out speedy improvements without getting confused by pointless subtleties. 

Utilized by the best 

Alright - Python isn't simply one more programming language. It should have something, which is the reason the business giants use it. Furthermore, that too for different purposes. Developers at Google use Python to assemble framework organization systems, parallel information pusher, code audit, testing and QA, and substantially more. Netflix utilizes Python web development services for its recommendation algorithm and media player. 

Massive community support 

Python has a steadily developing community that offers enormous help. From amateurs to specialists, there's everybody. There are a lot of instructional exercises, documentation, and guides accessible for Python web development solutions. 

Today, numerous universities start with Python, adding to the quantity of individuals in the community. Frequently, Python designers team up on various tasks and help each other with algorithmic, utilitarian, and application critical thinking. 

Progressive applications 

Python is the greatest supporter of data science, Machine Learning, and Artificial Intelligence at any enterprise software development company. Its utilization cases in cutting edge applications are the most compelling motivation for its prosperity. Python is the second most well known tool after R for data analytics.

The simplicity of getting sorted out, overseeing, and visualizing information through unique libraries makes it ideal for data based applications. TensorFlow for neural networks and OpenCV for computer vision are two of Python's most well known use cases for Machine learning applications.

Summary

Thinking about the advances in programming and innovation, Python is a YES for an assorted scope of utilizations. Game development, web application development services, GUI advancement, ML and AI improvement, Enterprise and customer applications - every one of them uses Python to its full potential. 

The disadvantages of Python web improvement arrangements are regularly disregarded by developers and organizations because of the advantages it gives. They focus on quality over speed and performance over blunders. That is the reason it's a good idea to utilize Python for building the applications of the future.

#python development services #python development company #python app development #python development #python in web development #python software development

Firebase Introduction with C#

https://youtu.be/7_1t_f3sNyc

#firebase #c# with firebase #firebase database #c# with firebase tutorials #c# with firebase database #asp.net with firebase database