Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

Python tests codecov

ShareYourCloning Backend API

This API is part of a bigger application, before going further, please go to the main project readme, where you can find an introduction.

This python API is built with FastAPI and is for in silico cloning.

Summary

Read main project readme first.

This API provides a series of entry points. The API documentation can be accessed here. You can use the documentation page to try some request directly on the browser. Otherwise, the API is open for you to make requests from a python script or command line at: https://shareyourcloning.api.genestorian.org/.

Getting started

If you want to quickly set up a local instance of the frontend and backend of the application, check getting started in 5 minutes in the main repository.

Running locally

You can install this as a python package:

# Create a virtual environment
python -m venv .venv
# Activate the virtual environment
source .venv/bin/activate
# Install the package from github (will be in pypi at some point)
pip install shareyourcloning
# Run the API (uvicorn should be installed in the virtual environment)
uvicorn shareyourcloning.main:app

Running locally if you want to contribute

For the management of the dependencies poetry is used, if you don't have it, visit https://python-poetry.org/.

In the project directory:

# This should install the dependencies and create a virtual environment
poetry install

# Install the pre-commit hooks
pre-commit install

# Activate the virtual environment
poetry shell

The virtual environment is installed in the project folder. This is convenient if you are using an IDE for development. For settings of vscode see the folder .vscode.

Now you should be able to run the api by running:

# The --reload argument will reload the API if you make changes to the code
uvicorn shareyourcloning.main:app --reload --reload-exclude='.venv'

Then you should be able to open the API docs at http://127.0.0.1:8000/docs to know that your API is working.

Running locally with docker 🐳

If you want to serve the full site (backend and frontend) with docker, check getting started in 5 minutes in the main repository.

If you want to serve only the backend from a docker container, an image is available at manulera/shareyourcloningbackend. The image is built from the Dockerfile in the root of this repository and exposes the port 3000. To run it:

docker build -t manulera/shareyourcloningbackend .
docker run -d --name backendcontainer -p 8000:8000 manulera/shareyourcloningbackend

If you don't want to download the repository and build the image, you can fetch the latest image from dockerhub (same image that is used in https://shareyourcloning.api.genestorian.org/)

docker pull manulera/shareyourcloningbackend
docker run -d --name backendcontainer -p 8000:8000 manulera/shareyourcloningbackend

The api will be running at http://localhost:8000, so you should be able to access the docs at http://localhost:8000/docs.

Connecting to the frontend

If you want to receive requests from the frontend, or from another web application you may have to include the url of the frontend application in the CORS exceptions. By default, if you run the dev server with uvicorn shareyourcloning.main:app --reload --reload-exclude='.venv', the backend will accept requests coming from http://localhost:3000, which is the default address of the frontend dev server (ran with yarn start).

If you want to change the allowed origins, you can do so via env variables (comma-separated). e.g.:

ALLOWED_ORIGINS=http://localhost:3000,http://localhost:3001 uvicorn shareyourcloning.main:app --reload --reload-exclude='.venv'

Similarly, the frontend should be configured to send requests to the backend address, see here.

Serving the frontend from the backend

You may prefer to handle everything from a single server. You can do so by:

  • Build the frontend with yarn build.
  • Copy the folder build from the frontend to the root directory of the backend, and rename it to frontend.
  • Set the environment variable SERVE_FRONTEND=1 when running the backend. By default this will remove all allowed origins, but you can still set them with ALLOWED_ORIGINS.
  • Set the value of backendUrl in frontend/config.js to /.
  • Now, when you go to the root of the backend (e.g. http://localhost:8000), you should receive the frontend instead of the greeting page of the API.

You can see how this is done in this docker image and docker-compose file.

Contributing 🛠️

Check contribution guidelines in the main repository for general guidelines.

For more specific tasks:

Running the tests locally

pytest -v -ks

Notes

Ping a particular library version from github:

poetry add git+https://github.com/BjornFJohansson/pydna#4fd760d075f77cceeb27969e017e04b42f6d0aa3

Generating API stubs

For the frontend, it may be useful to produce stubs (I use them for writing the tests). See how this is implemented by looking at the RecordStubRoute class in record_stub_route.py. To run the dev server and record stubs:

RECORD_STUBS=1 uvicorn shareyourcloning.main:app --reload --reload-exclude='.venv'

This will record the stubs (requests and responses) in the stubs folder.

Metadata

Release files for shareyourcloning 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shareyourcloning 0.1.0
File Size Uploaded
shareyourcloning-0.1.0.tar.gz 110.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shareyourcloning 0.1.0
File Interpreter ABI Platform
shareyourcloning-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 231.5 kB

Release files / shareyourcloning-0.1.0.tar.gz

Download URL shareyourcloning-0.1.0.tar.gz
Size 110.3 kB
Tags Source
SHA-256 checksum
How to use checksums
425e09126bb98706969e64095b6ddff6265db6889bf574773b2cf660215dd9ad
BLAKE2b-256 checksum
How to use checksums
aa695cdcd0f18cf92f95b09ded3f8ff381bbadef0daff2592e4bb42bb15b2f28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 13, 2024.

Transparency log

Release files / shareyourcloning-0.1.0-py3-none-any.whl

Download URL shareyourcloning-0.1.0-py3-none-any.whl
Size 121.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e0b73155ba32fa5266ff4c237a175cb38eb955397c3c4bed62cb3a3477f6903
BLAKE2b-256 checksum
How to use checksums
01e0181cc1289b6829d77564562849835563d0c1dcd46d19f001720bc513f33e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 13, 2024.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page