Skip to content

Latest commit

 

History

History
100 lines (72 loc) · 2.32 KB

File metadata and controls

100 lines (72 loc) · 2.32 KB

Using this example

Installation

Clone this repository{:target="_blank"} and install the dependencies. This project uses uv{:target="_blank"} for dependency management which should be installed on your system first.

Install the dependencies:

uv sync

Then switch to the virtual environment:

# On Linux:
source .venv/bin/activate

# On Windows:
.venv\Scripts\activate

Usage

Run the server using Uvicorn:

uvicorn main:app --reload

!!! note You can also run the server by just executing the main.py file:

```console
python main.py
```

or using the included `POE` alias:

```console
poe serve
```

Then open your browser at http://localhost:8000{:target="_blank"}.

There is only one endpoint available: /users. It returns a list of all users for a GET request and creates a new user for a POST request.

Local Postgres server using Docker

This example uses PostgreSQL{:target="_blank"} as the database. If you dont have a local PostgreSQL database running, you can start one with Docker{:target="_blank"} using the following command:

docker run \
  --rm   \
  --name  postgres \
  -p 5432:5432 \
  -e POSTGRES_USER=postgres \
  -e POSTGRES_PASSWORD=postgres \
  -e POSTGRES_DB=postgres \
  -d postgres

This will run a PostgreSQL database in a Docker container in the background. When you are finished and want to stop the database, run:

docker stop postgres

If needed, you can connect to the database managment by :

docker exec -it postgres psql -U postgres

This will allow you to edit or delete the database or records.

Use SQLite instead of PostgreSQL

For testing purposes, you can also use SQLite{:target="_blank"} instead of PostgreSQL. To do so, open the db.py file and comment out the PostgreSQL database in the DATABASE_URL environment variable and uncomment the SQLite database.

# DATABASE_URL = "postgresql+asyncpg://postgres:postgres@localhost/postgres"
DATABASE_URL = "sqlite+aiosqlite:///./test.db"