Firebase模块在Python中的应用
Firebase是Python提供的一种库,用于使用Firebase提供的各种服务。为了更好地理解Firebase库,我们首先需要了解Firebase以及Firebase提供的不同服务。Google的Firebase技术使开发人员能够创建移动和在线应用程序。它于2011年作为一个独立的业务开始。谷歌于2014年购买了该平台,它目前是他们用于应用程序创建的主要产品。
正如您可能知道的,Firebase是一种用于加速应用程序开发的谷歌工具。它提供了BaaS(后端即服务),这意味着Firebase处理云基础设施和所有后端需求。这使您能够更快地设计和部署应用程序。实时数据库、云Firestore和身份验证只是Firebase提供的一些优秀服务。它还支持托管并提供用于词语识别、图片标记等机器学习任务的API!Firebase是一套工具,允许您“构建、改进和发展您的应用程序”,它提供的工具涵盖了开发人员通常需要自己构建但不愿意构建的很多服务,因为他们更愿意专注于应用程序体验。分析、身份验证、数据库、配置、文件存储、推送消息等都是其服务的一部分。这些服务基于云,并且能够扩展,开发人员几乎不需要做额外的工作。
当我说“托管在云上”时,我指的是谷歌的后端组件,这些组件完全由其维护和管理。Firebase的客户端SDK直接与这些后端服务接口,无需任何中间件连接您的应用程序和服务之间。如果您正在使用Firebase数据库选择之一,则通常会在客户端应用程序中编写代码来查询数据库。然而,传统的应用程序开发通常涉及编写前端和后端代码。前端代码只需调用后端可访问的API端点,而后端代码处理繁重的工作。Firebase产品绕过了传统的后端,将任务放在了客户端上。Firebase控制台提供对每个产品的管理访问权限。
在这些SDK之上,还有一个名为FirebaseUI(Android、iOS、Web)的库,其中包含许多有用的工具,使Firebase编程更加简单。还有其他项目,用于封装用于Angular的Web SDK,如AngularFire。这些都是免费使用的。Firebase非常支持开放源代码。
Firebase使开发人员可以专注于创建令人惊叹的用户体验。您无需管理任何服务器。也不需要开发API。Firebase是您的服务器、API和数据存储,所有这些都被设计成可根据您的特定需求进行定制。是的,您可能偶尔需要利用谷歌云的其他部分来处理复杂的应用程序。Firebase不可能成为所有人的一切。但是,它很接近。
现在让我们来看看Firebase套件提供的不同服务或产品,所有这些服务或产品都是Google提供的Firebase套件的一部分。各种服务包括:
- 实时数据库 :Firebase实时数据库是一个在云中托管的数据库。数据以JSON格式保存并实时同步到所有连接的客户端。要获取和同步数据,大多数数据库需要进行HTTP请求。大多数数据库只在您特别请求时提供信息。连接您的应用程序到Firebase时,您不使用标准的HTTP进行连接。您使用WebSocket进行连接。相比WebSockets,HTTP速度要慢得多。您不需要执行许多WebSocket调用,因为一个单独的套接字连接是足够的。您的所有数据在单个WebSocket上自动同步,速度取决于客户端网络的处理能力。一旦有新的数据可用,Firebase会提供给您。当客户端保存对数据的修改时,更新后的数据几乎立即发送给所有关联的客户端。
- 文件存储 :Firebase Storage允许您保存二进制文件,最常见的是照片,但任何文件都可以直接从客户端传输到Google Cloud Storage!!!为了保护您的GCloud存储桶免受大众的侵扰,Firebase Storage拥有自己的安全限制,同时允许经授权的客户具有全面的写入权限。开发人员使用Firebase SDKs for Cloud Storage可以直接从客户端上传和获取文件。如果网络连接不稳定,客户端可以从上次中断的地方恢复进程,为消费者节省时间和带宽。Firebase云存储将您的文件保存在Google Cloud Storage存储桶中,可以从Firebase和Google Cloud访问它们。Firebase SDKs for Cloud Storage为您提供了从移动客户端上传和下载文件的自由。您还可以使用Google Cloud Storage API进行服务器端处理,如图像过滤和视频转码。由于Cloud Storage自动扩展,无需切换到其他提供商。了解更多有关我们的Google Cloud集成的优势。
- 认证: Firebase认证包含了内置的电子邮件/密码认证系统。它还支持通过OAuth2与Google、Facebook、Twitter和GitHub进行认证。在很大程度上,我们将集中讨论电子邮件/密码认证。Firebase中的OAuth2协议有很好的文档,基本上是复制粘贴。如果你曾经创建过认证系统,你会对此表示遗憾。自定义认证是一场灾难。在余生中,我将永远不会再写认证系统。Firebase认证是我一见钟情的,而这份爱从未褪色。我时不时会感到沮丧。我们偶尔会有分歧。但自带认证系统如同寒冷黑暗的深渊,我将永远难以忘怀。我为自己的幸福感到庆幸。由于Firebase认证可以直接与Firebase数据库连接,因此您可以使用Firebase认证来管理对数据的访问。这不是一个事后的附带说明。你会喜欢Firebase Auth的第二个原因就是因为这个。
- Hosting :Firebase Hosting 是一个开发者友好的在线内容托管服务。您可以使用单个命令 (内容分发网络) 快速部署 Web 应用,并向全球分发静态和动态内容。要在 Firebase 上开发和托管微服务,请使用 Firebase Hosting 和 Cloud Functions 或 Cloud Run。对于所有的静态文件,Firebase 提供了一个易于使用的托管解决方案。它使用 HTTP/2 从全球 CDN 传送这些文件。Firebase Hosting 是专为当今的 Web 开发人员设计的。随着 Angular 等前端 JavaScript 框架和 Jekyll 等静态生成工具的出现,网站和应用程序比以往任何时候都更加强大。Hosting 提供了您启动和管理网站和应用程序所需的基础架构、工具和资源,无论是一个基本的应用着陆页还是一个大型渐进式 Web 应用程序 (PWA)。您可以使用 Firebase CLI 将本地文件夹上的文件部署到我们的 Hosting 服务器上。除了传递静态信息之外,您还可以使用 Firebase 的云函数 (Cloud Functions for Firebase) 或云运行 (Cloud Run) 提供动态内容和为您的站点托管微服务。我们全球 CDN 的最近边缘服务器通过 SSL 连接来提供所有的材料。
- Cloud Firestore :Cloud Firestore 是 Firebase 和 Google Cloud 提供的一种多功能、可扩展的数据库,用于移动端、Web 端和服务器端的开发。它和 Firebase 实时数据库一样,使用实时监听器来保持数据在客户端应用程序间的同步,并为移动端和 Web 端提供离线支持,使您能够创建具有响应性的应用程序,无论网络延迟或互联网连接如何。Cloud Firestore 还可以无缝集成其他 Firebase 和 Google Cloud 技术,如 Cloud Functions。Cloud Firestore 是一个存储在云上的 NoSQL 数据库,您的 iOS、Android 和 Web 应用程序可以直接使用本地 SDK 进行访问。除了 REST 和 RPC API,Cloud Firestore 还支持本地 Node.js、Java、Python、Unity、C++ 和 Go SDK。根据 Cloud Firestore 的 NoSQL 数据模型,您可以将数据存储在具有映射到值的字段的文档中。这些文档被保存在集合中,集合是可以用来组织数据和构建查询的文档容器。从基本的字符和整数到复杂的嵌套结构,文档支持各种数据类型。您还可以通过在文档中创建子集合来设计随着数据库发展而扩展的分层数据结构。Cloud Firestore 数据模型接受您的应用程序所需的任何数据结构。
代码
# A sample python code to display the usage of the firebase module in the python code.
# All the required libraries are imported so that we can use different functions which are made available by these libraries
from firebase import firebase
import sys
from pprint import pprint
# Sample class is written which will have different functions representing the different operations that we perform on the firebase database, for each different functionality we have one separate function of this class which will perform that particular functionality gracefully
class MyFirebaseConnection:
# a constructor is written which is used to initialize various class variables of this class, the various variables which are initialized in the constructor are the firebase connector, record name, and the child record name. the firebase connector variable holds the URL of the firebase shared relational database on which we are going to perform different operations like storing the data reading the data deleting the data and modifying the auditing existing date
def __init__(self):
self.firebase_connector = None
self.root_record_name = "student_records"
self.child_record_name = "student_details"
# A function is written which will be used to connect to the firebase database, in this function the user is asked for the firebase database access link or URL, which is passed as a parameter to the firebase application method and with the help of this method establish a secure connection with the cloud database, so once the connection is established successfully we are using this object to perform various operations across the code
def connect_to_firebase_database(self):
print("Enter the Firebase Database Access link::")
db_url = input()
db_connection = firebase.FirebaseApplication(db_url, None)
self.firebase_connector = db_connection
print("Connection to the Database established successfully.")
# a function is written to write data to the cloud database in this function the user is asked to enter the data for a particular object which is going to be stored as a single entity in the cloud database, first of all, the user is asked for details and then the details entered by the user are encoded into a dictionary format and that dictionary is written to the firebase cloud database with the help of post function. The inner function is written to take input from the user. On successful writing of data to the firebase cloud database, a success message is prompted to the user.
def write_data_to_the_firebase_database(self):
print("Enter the data you want to add to the Firebase Database::")
# this is an inner function that is used to take various details of a student's records which we are going to store in our relational database, the user is asked for various details of a student like the name of the student, the roll number of the student and the marks of the student, on entering this particular details please details and code into a Python dictionary format and that dictionary object is returned as a return type of this in a function, and that the return dictionary object is going to be stored in the firebase cloud database.
def get_data():
print("Enter the name of the student:")
student_name = input()
print("Enter the rollno of the student:")
student_rollno = input()
print("Enter the marks of the student:")
student_marks = input()
student_data_dict = dict({
'student_name' : student_name,
'student_rollno' : student_rollno,
'student_marks' : student_marks
})
pprint(student_data_dict)
return student_data_dict
data_to_write_to_firebase_db = get_data()
self.firebase_connector.post("/{}/{}".format(self.root_record_name,self.child_record_name),data_to_write_to_firebase_db)
print("Data added sucessfully to the Firebase Database.")
# this function is used to read the data which is stored in the firebase cloud database, in this function all the records all data that we have stored in the cloud database are printed, the point to be noted here is that along with the EA dictionary object which we are storing in the cloud database there is a particular Hash ID that is getting mapped to a particular record and while printing we can see that ID which is associated with those records. the get function is used to retrieve the data from the firebase cloud database.
def read_data_from_the_firebase_database(self):
print("Data present in the Firebase Database::")
records_obtained = self.firebase_connector.get("/{}/{}".format(self.root_record_name,self.child_record_name),'')
for record in records_obtained:
pprint(record)
# This function is used to delete a particular record from the firebase cloud database, in this function the user is asked for the IT ID of the record that the user wants to delete from the firebase cloud database, on entering that particular ID off the record which user want to delete that particular record is deleted from the firebase cloud database with the help of the delete function provided by firebase library of the python, on the successful deletion of the desired record specified by the user is prompted with the success message indicating the successful deletion of the desired record.
def delete_data_from_the_firebase_database(self):
print("Enter the ID of the record that you want to delete from Firebase Database::")
record_id = input()
self.firebase_connector.delete("/{}/{}".format(self.root_record_name,self.child_record_name),record_id)
print("Record deleted successfully from the Firebase Database.")
# This function is used to update an already existing record from the firebase cloud database, In this method the user asked for a particular set of inputs that are required for this function to work properly, these inputs are the idea off the record for which we want to update something, and then the user is asked for the parameter of that record which the user want to update the parameter, in this case, could be anything like the name of the student roll number of the student or the marks of the student and then the user is asked for the new value of that particular record, on entering all these above-mentioned entries the record is updated with the new value by using the update function of the library.
def update_data_in_the_firebase_database(self):
print("Enter the ID of the record that you want to update in the Firebase Database::")
record_id = input()
print("Enter the what parameter of the record you want to update?")
parameter_to_update = input()
print("Enter the new value of the {},you want to update?".format(parameter_to_update))
new_value_of_parameter = input()
self.firebase_connector.put("/{}/{}/{}".format(self.root_record_name,self.child_record_name,record_id),parameter_to_update,new_value_of_parameter)
print("Record updated successfully from the Firebase Database.")
# The main function is written which will be used to create an object of the above-written clause and with the help of this creation, we can call the various methods which are written inside that class each of these methods depicting a particular functionality of the firebase cloud database. the different options or operations which are supported by the firebase cloud database are creating a new record in the cloud database, deleting an already existing record from the cloud database, reading and displaying all the records that are stored in that particular database, and updating a particular parameter of the already present record in the firebase cloud database for all these functionalities there are different functions provided by the firebase library of the python and we have written different functions in the above-written class for all this functionality to understand them better.
def main():
firebase_db_obj = MyFirebaseConnection()
while(True):
print("These are the possibilities given below; choose any one of them.::")
print("1. To establish a connection to the Firebase Database using the Firebase module of python.")
print("2. To write data to the Firebase Database using the Firebase module of python.")
print("3. To read data from the Firebase Database using the Firebase module of python.")
print("4. To delete data from the Firebase Database using the Firebase module of python.")
print("5. To update a data/record in the Firebase Database using the Firebase module of python.")
print("6. To terminate the code and stop the choices from being displayed.")
menu_choice = input()
menu_choice = int(menu_choice)
if menu_choice == 1:
firebase_db_obj.connect_to_firebase_database()
elif menu_choice == 2:
firebase_db_obj.write_data_to_the_firebase_database()
elif menu_choice == 3:
firebase_db_obj.read_data_from_the_firebase_database()
elif menu_choice == 4:
firebase_db_obj.delete_data_from_the_firebase_database()
elif menu_choice == 5:
firebase_db_obj.update_data_in_the_firebase_database()
elif menu_choice == 6:
sys.exit()
print("To continue with code execution, type [y] otherwise [n].")
continue_or_exit = input()
if continue_or_exit == 'y' or continue_or_exit == 'Y':
pass
elif continue_or_exit == 'n' or continue_or_exit == 'N':
sys.exit()
if __name__ == '__main__':
main()
输出:
These are the possibilities given below; choose any one of them.::
1. To establish a connection to the Firebase Database using the Firebase module of python.
2. To write data to the Firebase Database using the Firebase module of python.
3. To read data from the Firebase Database using the Firebase module of python.
4. To delete data from the Firebase Database using the Firebase module of python.
5. To update a data/record in the Firebase Database using the Firebase module of python.
6. To terminate the code and stop the choices from being displayed.
1
Enter the Firebase Database Access link::
https://xxxxxx-yyyyy.firebaseio.com
A connection to the Database was established successfully.
To continue with code execution, type [y] otherwise [n].
y
These are the possibilities given below; choose any one of them.::
1. To establish a connection to the Firebase Database using the Firebase module of python.
2. To write data to the Firebase Database using the Firebase module of python.
3. To read data from the Firebase Database using the Firebase module of python.
4. To delete data from the Firebase Database using the Firebase module of python.
5. To update a data/record in the Firebase Database using the Firebase module of python.
6. To terminate the code and stop the choices from being displayed.
2
Enter the data you want to add to the Firebase Database::
Enter the name of the student:
Nirnay
Enter the roll no of the student:
35
Enter the marks of the student:
92
{'student_marks': '92', 'student_name': 'Nirnay', 'student_rollno': '35'}
Data added sucessfully to the Firebase Database.
To continue with code execution, type [y] otherwise [n].
y
These are the possibilities given below; choose any one of them.::
1. To establish a connection to the Firebase Database using the Firebase module of python.
2. To write data to the Firebase Database using the Firebase module of python.
3. To read data from the Firebase Database using the Firebase module of python.
4. To delete data from the Firebase Database using the Firebase module of python.
5. To update a data/record in the Firebase Database using the Firebase module of python.
6. To terminate the code and stop the choices from being displayed.
2
Enter the data you want to add to the Firebase Database::
Enter the name of the student:
Rahul
Enter the roll no of the student:
21
Enter the marks of the student:
97
{'student_marks': '97', 'student_name': 'Rahul', 'student_rollno': '21'}
Data added sucessfully to the Firebase Database.
To continue with code execution, type [y] otherwise [n].
y
These are the possibilities given below; choose any one of them.::
1. To establish a connection to the Firebase Database using the Firebase module of python.
2. To write data to the Firebase Database using the Firebase module of python.
3. To read data from the Firebase Database using the Firebase module of python.
4. To delete data from the Firebase Database using the Firebase module of python.
5. To update a data/record in the Firebase Database using the Firebase module of python.
6. To terminate the code and stop the choices from being displayed.
2
Enter the data you want to add to the Firebase Database::
Enter the name of the student:
Priyanka
Enter the roll no of the student:
15
Enter the marks of the student:
89
{'student_marks': '89', 'student_name': 'Priyanka', 'student_rollno': '15'}
Data added sucessfully to the Firebase Database.
To continue with code execution, type [y] otherwise [n].
y
These are the possibilities given below; choose any one of them.::
1. To establish a connection to the Firebase Database using the Firebase module of python.
2. To write data to the Firebase Database using the Firebase module of python.
3. To read data from the Firebase Database using the Firebase module of python.
4. To delete data from the Firebase Database using the Firebase module of python.
5. To update a data/record in the Firebase Database using the Firebase module of python.
6. To terminate the code and stop the choices from being displayed.
3
Data present in the Firebase Database::
'8e606c6eca3711ec' : {'student_marks': '92', 'student_name': 'Nirnay', 'student_rollno': '35'}
'8e606c6eca3711fr' : {'student_marks': '97', 'student_name': 'Rahul', 'student_rollno': '21'}
'8e606c6eca3712gq' : {'student_marks': '89', 'student_name': 'Priyanka', 'student_rollno': '15'}
To continue with code execution, type [y] otherwise [n].
y
These are the possibilities given below; choose any one of them.::
1. To establish a connection to the Firebase Database using the Firebase module of python.
2. To write data to the Firebase Database using the Firebase module of python.
3. To read data from the Firebase Database using the Firebase module of python.
4. To delete data from the Firebase Database using the Firebase module of python.
5. To update a data/record in the Firebase Database using the Firebase module of python.
6. To terminate the code and stop the choices from being displayed.
5
Enter the ID of the record that you want to update in the Firebase Database::
8e606c6eca3711fr
Enter the what parameter of the record you want to update?
student_marks
Enter the new value of the student_marks, you want to update?
96
Record updated successfully from the Firebase Database.
To continue with code execution, type [y] otherwise [n].
y
These are the possibilities given below; choose any one of them.::
1. To establish a connection to the Firebase Database using the Firebase module of python.
2. To write data to the Firebase Database using the Firebase module of python.
3. To read data from the Firebase Database using the Firebase module of python.
4. To delete data from the Firebase Database using the Firebase module of python.
5. To update a data/record in the Firebase Database using the Firebase module of python.
6. To terminate the code and stop the choices from being displayed.
3
Data present in the Firebase Database::
'8e606c6eca3711ec' : {'student_marks': '92', 'student_name': 'Nirnay', 'student_rollno': '35'}
'8e606c6eca3711fr' : {'student_marks': '96', 'student_name': 'Rahul', 'student_rollno': '21'}
'8e606c6eca3712gq' : {'student_marks': '89', 'student_name': 'Priyanka', 'student_rollno': '15'}
To continue with code execution, type [y] otherwise [n].
y
These are the possibilities given below; choose any one of them.::
1. To establish a connection to the Firebase Database using the Firebase module of python.
2. To write data to the Firebase Database using the Firebase module of python.
3. To read data from the Firebase Database using the Firebase module of python.
4. To delete data from the Firebase Database using the Firebase module of python.
5. To update a data/record in the Firebase Database using the Firebase module of python.
6. To terminate the code and stop the choices from being displayed.
4
Enter the ID of the record that you want to delete from the Firebase Database::
8e606c6eca3712gq
Record deleted successfully from the Firebase Database.
To continue with code execution, type [y] otherwise [n].
y
These are the possibilities given below; choose any one of them.::
1. To establish a connection to the Firebase Database using the Firebase module of python.
2. To write data to the Firebase Database using the Firebase module of python.
3. To read data from the Firebase Database using the Firebase module of python.
4. To delete data from the Firebase Database using the Firebase module of python.
5. To update a data/record in the Firebase Database using the Firebase module of python.
6. To terminate the code and stop the choices from being displayed.
3
Data present in the Firebase Database::
'8e606c6eca3711ec' : {'student_marks': '92', 'student_name': 'Nirnay', 'student_rollno': '35'}
'8e606c6eca3711fr' : {'student_marks': '96', 'student_name': 'Rahul', 'student_rollno': '21'}
To continue with code execution, type [y] otherwise [n].
y
These are the possibilities given below; choose any one of them.::
1. To establish a connection to the Firebase Database using the Firebase module of python.
2. To write data to the Firebase Database using the Firebase module of python.
3. To read data from the Firebase Database using the Firebase module of python.
4. To delete data from the Firebase Database using the Firebase module of python.
5. To update a data/record in the Firebase Database using the Firebase module of python.
6. To terminate the code and stop the choices from being displayed.
6
解释:
上述代码中解释了Firebase库的不同功能的使用。在这段代码中,我们使用Python的Firebase库在Firebase云中创建了一个数据库。这段代码执行了各种操作,包括连接到Firebase云数据库,在成功连接到Firebase云数据库后,接下来的步骤是从用户获取输入数据,并将其转换为Python字典对象,然后将该特定字典对象写入Firebase云数据库,然后读取存储在Firebase云数据库中的所有数据。除了读取和写入之外,我们还可以从Firebase云数据库中删除已经存在的记录,还可以更新Firebase云数据库中已经存在的记录。然后编写了主要函数,用于创建上述子句的对象,并通过此创建,可以调用该类中编写的各种方法,其中每个方法表示Firebase云数据库的特定功能。 Firebase云数据库支持的不同选项或操作是在云数据库中创建新记录,从云数据库中删除已经存在的记录,读取和显示存储在该特定数据库中的所有记录以及更新Firebase云数据库中已经存在的记录的特定参数。对于所有这些功能,Firebase库提供了不同的功能,并且我们在上述类中编写了不同的函数,以更好地理解它们。
Firebase如此受开发人员欢迎的一个原因是它为开发人员提供了大量的优势,帮助它们节省时间,使他们可以将时间投入到其他任务上,而不是反复重新发明轮子。现在让我们快速浏览一下Firebase库的一些主要优势:
- 开发速度 :Firebase是一个很好的应用开发替代方案,可以帮助开发人员大大缩短应用开发上市时间。对于数据库和后端服务的设置和维护,大多数开发人员需要访问服务器和主机。构建应用程序,您将需要一个后端开发人员和一个前端开发人员。即使在后端和前端在各个阶段必须一起工作的较小系统中,这个是正确的。同时拥有前端和后端开发人员可能导致错误和困难,这可能会引发应用程序问题,并增加开发成本和复杂性。然而,使用Firebase使前端开发人员能够跟踪所有任务并缩短完成时间。所有这一切都是因为可供使用的数据存储、身份验证、警报、分析和其他服务。此外,Firebase提供了许多可供使用的服务,消除了开发人员编写样板代码、重新发明轮子或从头开始创建后端的需要。Firebase的高质量SDK、广泛的文档和活跃的社区将使前端开发人员能够轻松地将其集成到他们的代码库中。
- 由Google提供支持: Google是技术领域最知名和值得信赖的品牌之一,Firebase正是由Google背后支持。自被Google收购以来,Firebase已经经历了许多调整和进步,并发展成为现在可靠的平台。它利用Google Cloud和多种Google服务。现在,Firebase已成为Google Cloud Platform的一部分,在此与各种第三方服务连接并与其他Google Cloud服务完美协作。自收购以来,Google一直在Firebase上进行重大投资,使其功能更加强大。
- 开始免费: Firebase是一个免费的服务,允许用户使用他们的Google账号登录。Spark计划是免费的,并包括一系列功能,以帮助开发者入门。然后,他们可以根据实际需求选择Blaze计划。Firebase的免费入门能力是一个伟大的特点,也是它受欢迎的原因之一。Spark计划上的数据库读写限制相当宽松。另一个好处是Blaze计划考虑了初始的免费限制。想象一下你将在Blaze计划上托管20GB的存储空间的情况。由于免费限制为10GB,Firebase只会为额外的10GB收费。
- 服务的多样性 : Firebase还提供一系列广泛的产品,以帮助开发人员进行工作。Firestore和Firebase的实时数据库是两种数据库选择。同样,Firebase的集成云功能支持无服务器应用程序开发,并提供方便的云媒体存储。Firebase平台具有构建、发布和监控应用程序的功能,并覆盖整个应用程序开发周期。它还提供了吸引消费者并让他们在开发周期的最后阶段继续使用应用程序的方法。
- 无服务器架构 : 扩展和缩小服务器并不容易!特别是扩展数据库集群非常困难,改善大负载的性能需要经验丰富的专家的专业知识。Firebase解决了这个问题,提供了完全无服务器的环境。Firebase是一种无服务器设计,这意味着客户只需支付请求费用,无需维护或担心服务器基础设施。它与传统服务器不同,传统服务器必须始终运行。因为Firebase是一个无服务器平台,用户只在服务器被使用时收费。由于提高了效率,对可扩展性的担忧更少。采取亲自进行DevOps、安装、基础架构和容量规划的方法,给开发人员提供了更大的自由度。
- 前端友好 :Firebase受到全球开发者的青睐,因为它允许他们专注于编写移动应用的前端代码。Firebase最小化了对样板后端代码的需求,从而加快了应用的开发速度。Firebase简化了应用开发,同时降低了开销。开发者和企业还可以使用Firebase通过使用一种易于学习的单一技术来标准化后端环境。后端模式减少了支持所需的培训量,并允许前端开发者处理大部分工作。
- 用于机器学习 :机器学习即将彻底改变信息技术领域,它已经以各种方式开始。根据Gartner的数据,有30%的公司将在其操作的至少一个组件中使用机器学习。Firebase也很有用,因为它允许开发者使用机器学习。无论iOS和Android开发者的经验水平如何,他们都可以使用机器学习。Firebase带有一个包含文本识别、人脸检测、图片标注、条码扫描和其他移动平台功能的ML工具包。开发者可以根据应用开发需求选择云端和本地设备API。
- 易于Bug监控 :Crashlytics是Firebase的一个组件,是一个很好的工具,可以快速识别和解决问题。Firebase可以跟踪非致命和致命的错误,并根据故障对用户体验的影响提供报告。
- 更好的SEO :通过在Google搜索中提供应用链接,Firebase促进了应用索引,使用户可以重新与Google搜索进行互动。通过对应用进行索引,可以提高应用在搜索中的评级,使其被新用户发现并安装。Android Instant App是开发人员的一个很好选择,可以用来访问应用程序内容。
- 简便的备份 :Firebase通过频繁备份提供了最高级别的数据保护和可用性。通过依赖于该平台的自动备份功能,应用程序可以免受任何潜在数据丢失的威胁。对于Blaze计划用户,可以轻松配置实时数据库的自动备份。可以通过点击Firebase数据库的备份选项卡来访问自动备份设置。
Firebase的缺点
- 复杂的查询 :复杂查询的实现是用户在NoSQL数据库中遇到的另一个问题。尽管Firebase的Cloud Firestore在RTDB上有了显著改进,但对于某些客户来说,执行复杂的查询仍然是一个障碍。
- 只支持NoSQL :在Firebase的任何数据库选择中,都无法使用关系数据库。
- 国家限制 :Google Firebase的官方网站是https://firebase.google.com,并在多个国家受到限制。由于中国禁止使用.google.com和.googleapis.com的URI,Google和其他Google服务在中国被封锁和不可用。
- 没有社区支持 :因为Firebase不是一个开源的移动应用开发平台,对许多开发者来说它是一个糟糕的选择。由于Firebase是闭源的,用户无法编辑其源代码。因此,许多喜欢Firebase功能的开发者最终会使用其他平台。尽管该平台不是开源的,但在GitHub上有许多可用的库和SDK。这可能是Firebase最重要的限制,阻止了社区的发展、提高了灵活性水平,并为无法支付Firebase价格的开发者提供自托管选择。
因此,在本文中,我们了解了在Python中使用Firebase模块的用法。