1111
1212# SteamCMD API
1313
14- Read-only API interface for steamcmd app_info. Updates of this code are
15- automatically deployed via [ Github Actions ] ( https://github.com/ steamcmd/api/actions )
16- when a new version has been created on Github .
14+ Read-only API interface for steamcmd app_info. The official API is reachable on
15+ [ api.steamcmd.net ] ( https://api. steamcmd.net ) and it's documentation can be found
16+ on [ www.steamcmd.net ] ( https://www.steamcmd.net ) .
1717
1818## Self-hosting
1919
20- The easiest way to host the API yourself is using the free cloud platform
21- [ Fly.io] ( https://fly.io ) . Install the CLI according to the documentation:
22- [ https://fly.io/docs/hands-on/install-flyctl/ ] ( https://fly.io/docs/hands-on/install-flyctl/ ) .
23-
24- After installing, authenticate locally with the ` flyctl ` cli:
25- ``` bash
26- fly auth login
27- ```
28- Create the app and redis instances (choose your own names):
29- ``` bash
30- fly apps create < app-name>
31- fly redis create < redis-name>
32- ```
33- Retrieve the Redis connection URL (you will need this later):
34- ``` bash
35- fly redis status < redis-name>
36-
37- Redis
38- ID = xxxxxxxxxxxxxxxxxx
39- Name = api
40- Plan = Free
41- Primary Region = ams
42- Read Regions = None
43- Eviction = Enabled
44- Private URL = redis://default:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@fly-api.upstash.io < == Write the password down
45- ```
46- Set the required configuration environment variables:
47- ``` bash
48- fly secrets set --app < app-name> \
49- CACHE=True \
50- CACHE_TYPE=redis \
51- CACHE_EXPIRATION=120 \
52- REDIS_HOST=" fly-api.upstash.io" \
53- REDIS_PORT=6379 \
54- REDIS_PASSWORD=" xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
55- ```
56- Finally deploy the API Docker image with the latest code:
57- ``` bash
58- fly deploy --app < app-name> --image steamcmd/api:latest -e VERSION=1.0.0
59- ```
60- The version is optional and currently only required for the ` /v1/version ` endpoint.
61-
62- ## Container
63-
64- The API can easily be run via a Docker image which contains the API code and the
20+ The API can easily be run via a container image which contains the API code and the
6521` uvicorn ` tool to be able to respond to web requests. With every new version of
6622the API the Docker images is automatically rebuild and pushed to the Docker Hub:
6723``` bash
@@ -73,8 +29,16 @@ docker pull steamcmd/api:1.10.0
7329``` bash
7430docker run -p 8000:8000 -d steamcmd/api:latest
7531```
76- However during development, using Docker Compose is preferred. See the
77- [ Development] ( #development ) section for information.
32+ The API consists of 2 services; the ** Web** and the ** Job** service and the Redis
33+ cache. The ** Job** service and the Redis cache are both optional but are both required
34+ if you want to run the ** Job** service.
35+
36+ Details on how the official API is hosted can be found in the
37+ [ platform] ( https://github.com/steamcmd/platform ) repository. This repository contains
38+ all the infrastructure as code that is used to deploy the API on a Kubernetes cluster.
39+
40+ See the [ Development] ( #development ) section for more information on running
41+ the API and Job services directly via Python.
7842
7943## Configuration
8044
@@ -89,7 +53,7 @@ that you will need to set the corresponding cache settings for that type as well
8953when using the ** redis** type).
9054
9155All the available options in an ` .env ` file:
92- ```
56+ ``` shell
9357# general
9458VERSION=1.0.0
9559
@@ -109,34 +73,34 @@ REDIS_URL="redis://YourUsername:YourRedisP@ssword!@your.redis.host.example.com:6
10973
11074# logging
11175LOG_LEVEL=info
112-
113- # deta
114- DETA_BASE_NAME="steamcmd"
115- DETA_PROJECT_KEY="YourDet@ProjectKey!"
11676```
11777
11878## Development
11979
120- Run the api locally by installing a web server like uvicorn and running it :
80+ To develop locally start by creating a Python virtual environment and install the prerequisites :
12181``` bash
12282python3 -m venv .venv
12383source .venv/bin/activate
12484pip install -r requirements.txt
125- pip install uvicorn
126- cd src/
127- uvicorn main:app --reload
12885```
12986
130- The easiest way to spin up a complete development environment is using Docker
131- compose. This will build the image locally, mount the correct directory (` src ` )
132- and set the required environment variables. If you are on windows you should
133- store the repository in the WSL filesystem or it will fail. Execute compose up
134- in the root:
87+ Run the Web Service (FastAPI) locally by running the FastAPI development server:
13588``` bash
136- docker compose up
89+ source .venv/bin/activate
90+ cd src/
91+ fastapi dev web.py
13792```
13893Now you can reach the SteamCMD API locally on [ http://localhost:8000 ] ( http://localhost:8000 ) .
13994
95+ Run the Job Service (Celery) locally by running celery directly:
96+ ``` bash
97+ python3 -m venv .venv
98+ source .venv/bin/activate
99+ pip install -r requirements.txt
100+ cd src/
101+ celery -A job worker --loglevel=info --concurrency=2 --beat
102+ ```
103+
140104### Black
141105
142106To keep things simple, [ Black] ( https://github.com/python/black ) is used for code
0 commit comments