Part 1
Create and Read in Python
Overview
As you have learned, CRUD functionality is essential for interacting with databases. In Module Two, you gained practice using CRUD commands within the mongo shell. In order to develop a web application that connects a client-side user interface (such as a dashboard) to a database, it will help to develop a portable Python module that enables CRUD functionality for this data connection. In this milestone, you will begin creating a Python module that enables create and read functionality. You will finish developing the update and delete functionality for your Project One submission. This Python module will eventually be used to connect the user interface component to the database component of your dashboard in Project Two.
Note: This milestone requires you to use the “aacuser” account and password that you set up back in the Module Three milestone. If you did not successfully complete that milestone, follow the steps in Part II of the Module Three milestone to set up the “aacuser” account before beginning this milestone.
Prompt
After completing the readings for this module, you will implement the fundamental operations of creating and reading documents (the C and R of CRUD) in Python. You will use the PyMongo driver to create CRUD functional access to your document collection.
Upload the Austin Animal Center (AAC) Outcomes data set into MongoDB by importing a CSV file using the appropriate MongoDB import tool. This file is in the /usr/local/datasets/ directory in Apporto and the filename is “aac_shelter_outcomes.csv”. Use the database name “AAC” and collection name “animals”. Complete the import using the mongoimport tool and take screenshotsof both the import command and its execution.
Note: If you completed the Module Three milestone, you have already completed this step.
Next, you must develop a Python module in a PY file, using object-oriented programming methodology, to enable create and read functionality for the database. To support code reusability, your Python code needs to be importable as a module by other Python scripts.
Develop a CRUD class that, when instantiated, provides the following functionality:
A method that inserts a document into a specified MongoDB database and collection
Input -> argument to function will be set of key/value pairs in the data type acceptable to the MongoDB driver insert API call
Return -> “True” if successful insert, else “False”
A method that queries for documents from a specified MongoDB database and specified collection
Input -> arguments to function should be the key/value lookup pair to use with the MongoDB driver find API call
Return -> result in cursor if successful, else MongoDB returned error message
Important: Be sure to use find() instead of find_one() when developing your method.
As you develop your code, be sure to use industry standard best practices such as proper naming conventions, exception handling, and in-line comments. This will ensure that your code is easy to read and reusable for future projects.
TIP: Use the following sample code to get started. Note that the authentication to MongoDB is in the initialization method for the CRUD class.<code><strong>Example Python Code to Insert a Document</strong> from pymongo import MongoClient from bson.objectid import ObjectId class AnimalShelter(object): """ CRUD operations for Animal collection in MongoDB """ def __init__(self): # Initializing the MongoClient. This helps to # access the MongoDB databases and collections. self.client = MongoClient('mongodb://%s:%s@localhost:YOUR_PORT_NUMBER' % (username, password)) self.database = self.client['project'] # Complete this create method to implement the C in CRUD. def create(self, data): if data is not None: self.database.animals.insert(data) # data should be dictionary else: raise Exception("Nothing to save, because data parameter is empty") # Create method to implement the R in CRUD. </code>
Finally, create a Python testing script that imports your CRUD Python module to call and test the create and read instances of CRUD functionality. Be sure to use the username and password for the “aacuser” account for authentication when instantiating the class. This script should be created in a separate Jupyter Notebook IPYNB file, and should import and instantiate an object from your CRUD library to effect changes in MongoDB. After creating your script, execute it in Jupyter Notebook and take screenshots of the commands and their execution.
Guidelines for Submission
For your submission, you must include the code files for your Python module (PY file)and your Python testing script (IPYNB file). You must also submit a Microsoft Word document with your screenshots from Step 3.
part 2:
Anatomy of a README
Overview
README files are one way of documenting a development project. READMEs play an especially important role in open-source software, as they give the reader valuable information about the code you created. There is no standard README format. Much of the format depends on the scope of the software or project, so it’s really up to the developer what information should be included or provided. However, there are several elements that are part of good README files:
A description of the purpose of the project
A demonstration of how it works (its functional operations)
An identification of the tools used and a rationale for why those tools were chosen
An explanation of how to reproduce the project
In this assignment, you will explore and implement best practices for creating README files. This will help prepare you for the README files that you will need to create in Projects One and Two.
Prompt
This assignment provides you with some sample README files to explore and a README template. After you have reviewed the required documentation for creating a README file, you will learn about and implement best practices for creating your own README files.
Explore the following example README files: Zircon, BigFoot Dash App, and Plotly Dash. These READMEs come from a variety of different software projects and have different strengths and weaknesses. As you read, consider the following:
How clearly did each README file describe the purpose of their project?
What information did the README files include about the functionality of their project? What was helpful about this information? What could be improved?
What information did the README files include about the tools (software and libraries) that they used or how the user could reproduce the project?
Note: You do not need to submit anything related to this step. These are examples to guide your work in the next step.
After exploring the sample README files, begin creating your own README file for the CRUD Python module that you began creating in the Module Four milestone. Use the README template Word Document to get started. You must address each of the following:
Describe the purpose of the project by completing the About the Project and Motivation sections of the template.
Demonstrate the project’s functional operations by completing the Usage section. Be sure to include examples of your code and screenshots that show how your module works.
Document the tools used, identifying each tool and including your rationale for using these tools, by completing the Installation section. “Tools” include any software applications as well as any libraries used to complete your work.
Create instructions for reproducing the project by completing the Getting Started section. Discuss what the user of this CRUD Python module would need to do to get started. Some points to address are:
Briefly describe the database and user authentication that you set up in the Module Three milestone.
Briefly describe how you created the C and R portions of your Python module, any challenges you encountered, and how you overcame them.
Note: In this assignment, you only need to focus on creating a README for the create and read functionality of your CRUD Python module. You will continue developing the update and delete functionality as a part of Project One, which is due in Module Five. You will also need to update your README file for that assignment.