A FastAPI-based service for managing entities with MongoDB integration.
- Python 3.8 or higher
- MongoDB instance (local or cloud)
- pip (Python package manager)
- virtualenv (recommended)
- Clone the repository:
git clone <repository-url>
cd entities
- Create and activate a virtual environment:
python -m venv projenv
source projenv/bin/activate # On Unix/macOS
# OR
.\projenv\Scripts\activate # On Windows
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables:
Create a
.env
file in the root directory with the following variables:
MONGO_URI="your_mongodb_connection_string"
API_KEY="your_api_key"
RANDOM="path_to_project_root"
FILE_SVC_URI="http://localhost:8001"
FILE_SVC_APIKEY="your_file_service_api_key"
MONGO_URI
: MongoDB connection string (required)API_KEY
: API key for service authenticationRANDOM
: Project root directory pathFILE_SVC_URI
: File service endpoint URLFILE_SVC_APIKEY
: API key for file service authentication
Before running the service, it's recommended to run the test suite to ensure everything is working correctly:
- Install test dependencies:
pip install -r requirements.txt
- Run all tests:
# From the project root directory
python -m pytest
- Run specific unit tests:
# From the project root directory
python -m pytest tests/unit_tests.py -v
If you encounter errors while running tests:
- Ensure all dependencies are installed:
pip install -r requirements.txt
- Check if the virtual environment is activated:
# On Unix/macOS
source projenv/bin/activate
# On Windows
.\projenv\Scripts\activate
- Verify the project structure:
entities/
├── src/
│ └── app/
│ ├── core/
│ ├── models/
│ ├── schemas/
│ └── __init__.py
├── tests/
│ ├── __init__.py
│ ├── conftest.py
│ └── unit_tests.py
├── pyproject.toml
└── requirements.txt
-
If you get import errors:
- Make sure you're running the tests from the project root directory
- Use
python -m pytest
instead of justpytest
- Check that all
__init__.py
files are present in the necessary directories
-
For MongoDB-related test failures, ensure your MongoDB instance is running and the connection string in
.env
is correct.
- Start the service:
uvicorn main:app --reload
The service will be available at http://localhost:8000
- The project uses
ruff
for linting - Tests can be run using
pytest
- API documentation is available at
/docs
when the service is running
entities/
├── src/ # Source code
├── tests/ # Test files
├── requirements.txt # Project dependencies
├── main.py # Application entry point
└── .env # Environment configuration
See the LICENSE file for details.