A REST API to pilot the Ecotaxa pipelines
pip install fastapi
pip install pydantic
pip install "uvicorn[standard]"
<!-- pip3 install opencv-python -->
pip install opencv-python
pip install requests
pip install numpy
uvicorn main:app --reload
For detailed installation instructions, please refer to the Installation Guide.
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python -m uvicorn main:app --reloadThe application uses the following environment variables:
APP_ENV: Determines which configuration to use (developmentorproduction). Defaults todevelopment.WORKING_DIR: The working directory where the application will look for configuration files and other resources. Defaults to the current working directory.SECRET: The secret key used for JWT token signing and verification. If not set, a default value is used, but it's strongly recommended to set this to a secure, unique value in production environments.
You can set these environment variables before running the application:
# Set the environment to production
export APP_ENV=production
# Set the working directory
export WORKING_DIR=/path/to/your/working/directory
# Set the secret key for JWT token signing and verification
export SECRET="your-secure-secret-key"
# Run the application
python -m uvicorn main:app --reloadOr you can set them when running the application:
APP_ENV=production WORKING_DIR=/path/to/your/working/directory SECRET="your-secure-secret-key" python -m uvicorn main:app --reloadhttp://127.0.0.1:8000/docs http://127.0.0.1:8000/redoc
ssh niko
cd ~/complex/DEEP-OC-multi_plankton_separationdocker build -t deephdc/uc-ecotaxa-deep-oc-multi_plankton_separation .~/complex/DEEP-OC-multi_plankton_separation$
docker run -ti -p 5000:5000 -p 6006:6006 -p 8888:8888 deephdc/uc-ecotaxa-deep-oc-multi_plankton_separation ~/complex/DEEP-OC-multi_plankton_separation$
docker run -d -ti -p 5000:5000 -p 6006:6006 -p 8888:8888 deephdc/uc-ecotaxa-deep-oc-multi_plankton_separation ~/complex/DEEP-OC-multi_plankton_separation$
docker run -d -ti -p 5000:5000 -p 6006:6006 -p 8889:8888 deephdc/uc-ecotaxa-deep-oc-multi_plankton_separation In VSCode Thumder plugin, use the collection named Happy Pipeline
- to see if server alive test DEEP plankton separation - niko alive ? : to see if multi_plankton_separation is alive on Niko server
Built it
docker build -t gateway_api .Run it
docker run -p 8000:8000 -v /Users/sebastiengalvagno/piqv/plankton/:/app/data --name happy_pipeline gateway_api
when use Docker use .env.production else .env.development
at this moment, I can't run in docker because the path are linked to other apps then it can't find the file
a possibility, to use docker, is to make the very long local path in the container and use .env.development
make a tunnel before open on with local address, port do not pass throught the VPN
ssh -f niko -L 5001:localhost:5000 -N
open http://localhost:5001/uicd complex
git clone https://github.com/ai4os-hub/zooprocess-multiple-separator.git
cd zooprocess-multiple-separator/
docker build -t zooprocess-multiple-separator:1 .
docker build --no-cache -t zooprocess-multiple-separator:lastest .
docker run -d -ti -p 5000:5000 -p 6006:6006 -p 8888:8888 zooprocess-multiple-separator:1no detach mode to see error
docker run -ti -p 5000:5000 -p 6006:6006 -p 8888:8888 zooprocess-multiple-separator:1
openapigenerator generate -i http://localhost:5000/openapi.json -g python -o ./src
The generation of tests can be controlled using the test_config.json file in the project root directory. See TEST_GENERATION.md for more information.
python3 -m venv test_venv
source test_venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pytestor one test file
pytest tests/test_file.pyadd -v for verbose mode to see a list of test functions
Run only one test function
pytest tests/test_file.py::test_function_nameThe project uses mypy for static type checking. Mypy helps catch type-related errors before runtime by analyzing type annotations in the code.
To run mypy on the project:
# Install mypy if not already installed
pip install -r requirements.txt
# Run mypy on the entire src directory
mypy src
# Run mypy on a specific file
mypy src/path/to/file.pyMypy is configured using the mypy.ini file in the project root. The configuration includes:
- Python version set to 3.9
- Warning settings for returning Any types and unused configs
- Type checking for untyped definitions
- Ignoring missing imports for common libraries (numpy, pandas, matplotlib, etc.)
When adding new code to the project, consider adding type annotations to improve code quality and maintainability. For example:
def add_numbers(a: int, b: int) -> int:
return a + bFor more information on Python type annotations, see the mypy documentation.
The application uses SQLAlchemy as an ORM (Object-Relational Mapping) to interact with the SQLite database. This provides a more Pythonic way to work with the database and makes it easier to maintain and extend the database schema.
Database models are defined in src/db_models.py. Each model represents a table in the database and inherits from the SQLAlchemy Base class.
Example model:
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Example(Base):
__tablename__ = "example"
id = Column(Integer, primary_key=True)
name = Column(String, nullable=False)
value = Column(String)There are two ways to interact with the database:
- Using the backward-compatible
SQLiteDBclass (recommended for existing code):
from src.local_db.sqlite_db import SQLiteDB
# Using the context manager
with SQLiteDB() as db:
# Execute raw SQL queries
cursor = db.execute("SELECT * FROM example")
results = cursor.fetchall()- Using the new
SQLAlchemyDBclass (recommended for new code):
from src.local_db.sqlite_db import SQLAlchemyDB
from src.local_db.models import Example
# Using the context manager
with SQLAlchemyDB() as db:
# Create a new record
example = Example(name="test", value="value")
db.session.add(example)
db.session.commit()
# Query records
results = db.session.query(Example).filter_by(name="test").all()See the example script in examples/sqlalchemy_example.py for a complete example of using SQLAlchemy in the project.
The application provides a command-line interface (CLI) for various administrative tasks. The CLI is built using Typer and provides a user-friendly interface with rich formatting.
The User Management CLI allows you to add, update, remove, and list users in the database.
Make sure you have installed the required dependencies:
pip install -r requirements.txt# Show help
python -m commands.user_cli --help
# Add a new user
python -m commands.user_cli add --name "John Doe" --email "john@example.com"
# You will be prompted to enter and confirm a password
# Update an existing user
python -m commands.user_cli update --id "user_id" --name "New Name" --email "new@example.com"
# If you want to update the password, you will be prompted to enter and confirm it
# Remove a user
python -m commands.user_cli remove --id "user_id"
# You will be asked to confirm the removal unless you use the --force option
# List all users
python -m commands.user_cli list-
add: Add a new user to the database--name: User's full name (required)--email: User's email address (required)--password: User's password (will be prompted if not provided)--confirm-password: Confirm password (will be prompted if not provided)
-
update: Update an existing user in the database--id: User ID (required)--name: User's new name (optional)--email: User's new email address (optional)--password: User's new password (optional, will be prompted if provided)
-
remove: Remove a user from the database--id: User ID (required)--forceor-f: Force removal without confirmation (optional)
-
list: List all users in the database