SwiftComp-API is a FastAPI-based backend designed to perform calculations related to composite laminate materials. It exposes various endpoints for computing engineering constants, plate properties, 3D laminate properties, and more. This API is suitable for researchers, engineers, and developers working in composite materials and structural analysis.
- Versioned API: Support for multiple versions of the API, with versioning (v1, v2) for backward compatibility.
- Material Property Calculations: Endpoints to calculate various laminate engineering constants and composite properties.
- Lightweight & Fast: Built using FastAPI, ensuring high performance and minimal latency.
- Modular Architecture: Separation of concerns using routers, services, and utility functions for better maintainability.
- Extensible: Easy to add new endpoints and services for additional material computations.
- FastAPI: A modern, fast (high-performance) web framework for building APIs with Python 3.7+ based on standard Python-type hints.
- Python 3.7: Programming language used to implement the logic.
- Pytest: A robust testing framework for Python.
- Uvicorn: ASGI server used for serving FastAPI applications.
- Virtual Environment (venv): For dependency isolation.
The SwiftComp API is deployed online: https://swiftcomp-api-7327e882adaf.herokuapp.com
You can access API documentation at:
- Swagger UI: https://swiftcomp-api-7327e882adaf.herokuapp.com/docs
- ReDoc: https://swiftcomp-api-7327e882adaf.herokuapp.com/redoc
- Docker
- Clone the repository:
git clone https://github.com/wenbinyugroup/swiftcomp-api.git
cd swiftcomp-api
- Building the Docker Image: You can build a Docker image for the FastAPI app using the following command:
docker build -t swiftcomp-api .
- Running the Docker Container: Once the image is built, you can run the application in a Docker container:
docker run -d -p 8000:8000 swiftcomp-api
This will run the SwiftComp API app in a container and map port 8000 from the container to your local machine. You can access the application at http://localhost:8000.
- Running Tests Inside the Docker Container: To run the tests inside the running Docker container:
docker exec $(docker ps -q -f ancestor=swiftcomp-api) bash -c "PYTHONPATH=./ pytest"
This command sets the PYTHONPATH
and runs pytest
inside the running Docker container.
- Monitoring Logs: To monitor the logs from the running Docker container in real time:
docker logs -f <container_id_or_name>
You can get the container ID or name by running:
docker ps
To set up the project locally, follow these steps:
- Python 3.7 or higher.
- Git installed on your system.
- Clone the repository:
git clone https://github.com/wenbinyugroup/swiftcomp-api.git
cd swiftcomp-api
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install the dependencies:
pip install -r requirements.txt
- Run the FastAPI application locally:
uvicorn app.main:app --reload
This will start the SwiftComp API server at http://127.0.0.1:8000.
- Testing:
The repository includes unit tests using pytest
. To run the tests:
- Ensure you are in the virtual environment.
- Run the following command:
PYTHONPATH=./ pytest
FastAPI automatically generates interactive API documentation using Swagger and Redoc. Once the server is running, you can access the documentation at:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
- GET /: Root endpoint, returns a welcome message.
- POST /api/v1/lamina_engineering_constants: Calculates the lamina engineering constants based on the provided material properties.
- POST /api/v1/laminate_plate_properties: Calculates the laminate plate properties.
- POST /api/v1/laminate_3d_properties: Computes the 3D properties of laminate.
- POST /api/v1/udfrc_properties: Calculates UDFRC properties.
We welcome contributions to SwiftComp-API! Here's how you can help:
- Fork the repository.
- Create a new feature branch:
git checkout -b feature/your-feature-name
- Commit your changes:
git commit -m "Add your message"
- Push to the branch:
git push origin feature/your-feature-name
- Create a pull request: Describe the changes you’ve made.
This project is licensed under the MIT License. See the LICENSE file for more details.