This repository contains a simple setup for running a MongoDB instance using Docker and Docker Compose. It also includes a basic Python script to test the connection to the MongoDB server.
Before you begin, ensure you have the following installed on your system:
Follow these steps to get your MongoDB server running:
Clone this repository to your local machine:
git clone https://github.com/jhon0010/python-examples.git
cd python-examples
From the root of the cloned directory, run:
docker compose up -d
This command starts a MongoDB instance in a Docker container. The -d flag runs the container in detached mode.
Check if the MongoDB container is running:
docker ps
You should see the MongoDB container listed.
To stop the MongoDB Docker container, run:
docker compose down
-
Set up a virtual environment (optional but recommended):
- Create a new directory for your project.
- Open a terminal or command prompt and navigate to the project directory.
- Create a virtual environment using the following command:
python3 -m venv myenv
- Activate the virtual environment:
- On macOS and Linux:
source myenv/bin/activate
- On Windows:
myenv\Scripts\activate
- On macOS and Linux:
-
Install all the required dependencies:
- While inside the virtual environment, install the requirements using pip:
pip install -r requirements.txt
- While inside the virtual environment, install the requirements using pip:
Using uvicorn to run the file app with the module app in the port 8000.
The reload flag is used to reload the server automatically when the code is changed.
uvicorn app:app --reload
Go to the test folder and execute the command:
pytest
Go to the url http://localhost:8000/docs
The Dockerfile and docker-compose.yml files are configured to use the default MongoDB port 27017.
You can run the data scripts to play with the orders CSV file. The script is designed to read the CSV file and perform some operations on it. To run the data scripts, execute the following command:
python3 src/data/pandas_polars.py
python3 src/data/matplot_example.py
You can find other python scripts in the src/data
directory that interact with the orders.csv
file.
This will read the orders.csv
file and perform the operations defined in the script.
To run the load tests using Locus, you can use the following command:
locust -f test/locus_test/locus_user_api_test.py
This command will start the Locus web interface, which you can access at http://localhost:8089
to configure and run your load tests.
To run the math benchmark script, you can use the following command:
python3 tests/benchmark/main.py