Description β’ Quickstart β’ Project Structure β’ Stack
The main goal of this project is to conveniently and quickly receive translations of texts.
You can get translations and detect the language of the input text, both individually (single) and for the whole document (Google Sheet).
Also, the project allows you to get valid proxies through separate endpoints.
Available languages for translation: English
, German
, Italian
, Ukrainian
, Norwegian
and Japanese
.
Available providers for translation: Google Translate
, Libre Translate
, MyMemory
and DeepL
.
The project is completely asynchronous, has an admin panel, integration with Mongo, Postgres and Redis.
If necessary, you can download the translations attached to the original Google sheet through a separate endpoint.
-
Clone the repo and navigate to the root folder.
-
Create and activate a python3 virtualenv via your preferred method or with:
make ve
- For remove virtualenv:
make clean
-
If you setup virtualenv on your own - install the dependencies. Run:
pip install -r requirements.txt
-
Install pre-commit hooks to ensure code quality checks and style checks:
make install_hooks
-
You can also use these commands during dev process:
-
To run mypy checks:
make types
-
To run flake8 checks:
make style
-
To run black checks:
make format
-
To run together:
make lint
-
-
-
Replace
.env.example
with real.env
, changing placeholdersCURRENT_ENV=<staging|rc|production> SECRET_KEY=changeme REDIS_HOST=<redis-host> REDIS_PASSWORD=<redis-password> REDIS_PORT=<redis-port> REDIS_DB=<redis-db> REDIS_KEY=<redis-key> MONGO_HOST=<mongo-host> MONGO_DB=<mongo-db> MONGO_USER=<mongo-user> MONGO_PASSWORD=<mongo-password> MONGO_TASKS_COLLECTION=<mongo-tasks-collection> MONGO_USERS_COLLECTION=<mongo-users-collection> POSTGRES_HOST=<postgres-host> POSTGRES_PORT=<postgres-port> POSTGRES_DB=<postgres-db> POSTGRES_USER=<postgres-user> POSTGRES_PASSWORD=<postgres-password> TG_BOT_TOKEN=<tg-bot-token> TG_CHAT_ID=<tg-chat-id> MYMEMORY_EMAIL=<email-for-mymemory> DETECT_LANGUAGE_API_KEY=<detect-language-api-key> TCP_CONNECTOR_LIMIT=<tcp-connector-limit> ASYNC_TRANSLATION_TASKS_NUM=<async-translation-tasks-num> MAX_CONCURRENT_TASKS=<max-concurrent-tasks> RUN_BACKGROUND_TASKS=<1|0> SCHEDULER_TASK_INTERVAL=<seconds-interval>
-
Export path to Environment Variables:
export PYTHONPATH='.'
-
Run following commands to make migrations anc create admin user:
piccolo migrations forwards all piccolo user create
-
Start the Fjord API App:
-
Run server with test settings:
make runserver-test
-
Run server with dev settings:
make runserver-dev
-
Run server with prod settings:
makerunserver-prod
You will see something like this:
$ uvicorn main.app:app --reload INFO: Uvicorn running on http://127.0.0.1:5000 (Press CTRL+C to quit) INFO: Started reloader process [28720] INFO: Started server process [28722] INFO: Waiting for application startup. INFO: Application startup complete.
About the command
uvicorn main:app --reload
...The command
uvicorn main.app:app
refers to:main
: the filemain.py
(the Python "module").app
: the object created inside ofmain.py
with the lineapp = FastAPI()
.--reload
: make the server restart after code changes. Only do this for development.
-
-
If everything is fine, check this endpoint:
curl -X "GET" http://host:port/api/v1/status
Expected result:
{ "success": true, "version": "<version>", "message": "Fjord API" }
This shows the structure of the Ataman App.
fjord-api
βββ main # primary app folder
β βββ api # this houses for API packages
β β βββ routes # this is where all the routes live
β β β βββ __init__.py # empty init file to make the routes folder a package
β β β βββ auth.py # module with auth endpoint
β β β βββ proxies.py # module with proxy utils endpoint
β β β βββ status.py # module with health check endpoint
β β β βββ tasks.py # module with endpoints to handle translation task
β β β βββ translation.py # module with translation utils endpoint
β β βββ __init__.py # empty init file to make the api folder a package
β β βββ background.py # file containing all background tasks
β β βββ routes.py # manages all routers in the project
β βββ apps # this houses for Piccolo settings + template endpoints
β β βββ home # settings for Home App
β β β βββ piccolo_migrations # this houses for postgres migrations
β β β β βββ __init__.py # empty init file to make the piccolo_migrations folder a package
β β β βββ templates # jinja temolates for Home App
β β β β βββ index.html.jinja # home page template
β β β βββ __init__.py # empty init file to make the home folder a package
β β β βββ endpoints.py # endpoint settings for home page
β β β βββ piccolo_app.py # general piccolo app config
β β βββ __init__.py # empty init file to make the apps folder a package
β βββ const # store all the consts necessary for the application
β β βββ __init__.py # empty init file to make the const folder a package
β β βββ common.py # common consts
β β βββ proxies.py # consts for proxy services
β β βββ translator.py # consts for translation services
β βββ core # this is where the configs live
β β βββ settings # home for all setting files
β β β βββ __init__.py # empty init file to make the settings folder a package
β β β βββ app.py # base application settings
β β β βββ base.py # contains base app setting class and app envs
β β β βββ development.py # development app settings
β β β βββ production.py # production app settings
β β β βββ test.py # test app settings
β β βββ __init__.py # empty init file to make the config folder a package
β β βββ config.py # sample config file
β β βββ dependencies.py # auth dependency
β β βββ exceptions.py # app exception handlers
β β βββ integrations.py # module for project 3rd parties services
β β βββ logging.py # module configuration custom logger
β β βββ security.py # auth security utils
β βββ db # this is where the repositories logic live
β β βββ models # postgres models
β β β βββ __init__.py # empty init file to make the models folder a package
β β β βββ postgres.py # contains postgres models
β β βββ repositories # home for all repository files
β β β βββ __init__.py # empty init file to make the repositories folder a package
β β β βββ base.py # contains base repositories classes
β β β βββ proxies.py # repository to manipulate with proxies in Redis
β β β βββ tasks.py # repository to manipulate with translation tasks from Mongo collection
β β β βββ users.py # repository to manipulate with users from Mongo collection
β β βββ __init__.py # empty init file to make the repositories folder a package
β β βββ clients.py # provide client for MongoDB, Elasticsearch, etc.
β β βββ connections.py # process Postgres database connections
β β βββ errors.py # module for custom database errors
β βββ schemas # this is where the schemas live
β β βββ __init__.py # empty init file to make the schemas folder a package
β β βββ auth.py # users item schema
β β βββ common.py # contains common schemas
β β βββ notifier.py # notifier error schema
β β βββ proxies.py # proxy item schema
β β βββ status.py # health check schema
β β βββ tasks.py # schemas for translation tasks
β β βββ translation.py # single translation/detection schemas
β βββ services # this is where services live
β β βββ common # home for all main services
β β β βββ __init__.py # empty init file to make the common folder a package
β β β βββ proxy.py # proxy pool service
β β β βββ translation.py # service for single translation/detection
β β βββ extra # home for all extra services
β β β βββ proxynator.py # module to gather fresh proxies
β β β β βββ crawlers # crawlers logic
β β β β β βββ public # public crawlers
β β β β β β βββ __init__.py # empty init file to make the public folder a package
β β β β β β βββ * # different crawlers
β β β β β βββ __init__.py # empty init file to make the crawlers folder a package
β β β β β βββ base.py # abstract crawler class with all main proxy getter logic
β β β β βββ __init__.py # empty init file to make the proxynator folder a package
β β β β βββ main.py # fetching new fresh proxies and add them to Redis
β β β βββ translator.py # module with translation providers
β β β β βββ providers # providers logic
β β β β β βββ __init__.py # empty init file to make the crawlers folder a package
β β β β β βββ base.py # abstract provider class with all main translation getter logic
β β β β β βββ deepl.py # logic to get translation from DeepL provider
β β β β β βββ google.py # logic to get translation from Google Translate provider
β β β β β βββ libre.py # logic to get translation from LibreTranslate provider
β β β β β βββ mymemory.py # logic to get translation from MyMemory provider
β β β β βββ __init__.py # empty init file to make the proxynator folder a package
β β β β βββ main.py # general logic to get single/multiple translations
β β β βββ __init__.py # empty init file to make the extra folder a package
β β β βββ auth.py # handles users auth
β β β βββ errors.py # handles async sessions and possible errors
β β β βββ notifier.py # service for sending notifications to Telegram
β β βββ __init__.py # empty init file to make the services folder a package
β β βββ executor.py # translation task executor
β β βββ scheduler.py # translation task scheduler
β β βββ tasks.py # service to handle translation tasks
β βββ static # contains static files
β βββ *.css, *.js, *ico # different static files like .css, .js or images
β βββ utils # this is where the utils live
β β βββ __init__.py # empty init file to make the utils folder a package
β β βββ common.py # contains common utils
β β βββ proxies.py # utils to check/convert proxies
β β βββ tasks.py # includes tools for generating random IDs and form error messages
β βββ __init__.py # empty init file to make the main folder a package
β βββ app.py # main file where the fastAPI() class is called
βββ .env # env file containing app variables
βββ .env.test # env file containing app test variables
βββ .pre-commit-config.yaml # describes what repositories and hooks are installed
βββ docker-compose.yml # docker-compose file
βββ Dockerfile # prod Dockerfile
βββ Makefile # shell commands for convenient project use
βββ piccolo_conf.py # piccolo config (app registry, engine)
βββ pyproject.toml # pep-518 compliant config file
βββ requrements-ci.txt # pinned ci dependencies
βββ requirements-prod.txt # pinned prod dependencies
βββ requirements.txt # pinned app dependencies
βββ setup.cfg # linter config file
βββ version.py # app version file
- Β FastAPI
- Β aiohttp
- Β aioredis
- Β Piccolo
- Β PyMongo
- Β Jinja
- Β Pydantic
- Β Starlette
- Β Uvicorn
- Β graypy
- Β Sentry
- Gunicorn
π Jack Shendrikov π |