Skip to content

Commit 792d035

Browse files
authored
Merge pull request #922 from sanders41/docs
Update docs for FastAPI
2 parents 489a5b2 + d236288 commit 792d035

File tree

2 files changed

+95
-6
lines changed

2 files changed

+95
-6
lines changed

CONTRIBUTING.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ git pull upstream main --ff-only
6666
#### Run linting
6767

6868
```sh
69-
cargo clippy --all-targets
69+
cargo clippy
70+
```
71+
72+
To check with the FastAPI feature enabled
73+
74+
```sh
75+
cargo clippy -F fastapi
7076
```
7177

7278
#### Run the code formater
@@ -91,18 +97,35 @@ To run the tests:
9197
cargo insta test
9298
```
9399

100+
To run tests with the fastapi feature enabled
101+
102+
````sh
103+
cargo insta test -F fastapi
104+
94105
If the code change is expected to update a snapshot, for example when updating a default
95106
dependency, run the tests with the verify flat and check that the new snapshots are correct, then
96107
accept them.
97108

98109
```sh
99110
cargo insta test --verify
111+
````
112+
113+
For the fastapi feature
114+
115+
```sh
116+
cargo insta test --verify -F fastapi
100117
```
101118

102119
#### Ensure the code compiles
103120

104121
```sh
105-
cargo check --all-targets
122+
cargo check
123+
```
124+
125+
For the fastapi feature
126+
127+
```sh
128+
cargo check -F fastapi
106129
```
107130

108131
Be sure to run all these checks before submitting your pull request.
@@ -120,7 +143,7 @@ just lint
120143
To run tests:
121144

122145
```sh
123-
just test
146+
just test-all
124147
```
125148

126149
To run tests and review snapshots:
@@ -129,6 +152,12 @@ To run tests and review snapshots:
129152
just test-review
130153
```
131154

155+
To run tests with the FastAPI feature enabled and review snapshots:
156+
157+
```sh
158+
just test-review-fastapi
159+
```
160+
132161
To see a full list of `just` commands run `just --list`
133162

134163
## Committing your code

README.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
Generates a Python project structure with github actions for continuous integration and continuous
77
deployment. Both pure Python projects and Python projects with Rust modules using PyO3 can be
8-
created.
8+
created. Addtionally FastAPI projects can be generated.
99

1010
## Pure Python project included packages
1111

@@ -34,6 +34,25 @@ Dev packages:
3434
- [justfile](https://github.com/casey/just) for running commands (to use this you will need to
3535
install just)
3636

37+
## FastAPI projects include
38+
39+
- [asyncpg](https://github.com/MagicStack/asyncpg) for interacting with PostgreSQL
40+
- [camel-converter](https://github.com/sanders41/camel-converter) for converting to and from
41+
camel/snake case in Pydantic models when serializing/deserializing JSON
42+
- [fastapi](https://github.com/fastapi/fastapi)
43+
- [granian](https://github.com/emmett-framework/granian) for handling the web requests
44+
- [httptools](https://github.com/MagicStack/httptools) for faster http parsing
45+
- [loguru](https://github.com/Delgan/loguru) for logging
46+
- [orjson](https://github.com/ijl/orjson) for faster JSON serization/deserilization
47+
- [pwdlib](https://github.com/frankie567/pwdlib) for password hashing
48+
- [pydantic](https://github.com/pydantic/pydantic) for model validation
49+
- [pydantic-settings](https://github.com/pydantic/pydantic-settings) for managing settings
50+
- [uvloop](https://github.com/MagicStack/uvloop) for enhanced performance (not available on Windows)
51+
- [postgresql](https://www.postgresql.org/) for the database layer
52+
- [valkey](https://github.com/valkey-io/valkey) for the caching layer
53+
- [traefik](https://github.com/traefik/traefik) for reverse proxy
54+
- [sqlx](https://github.com/launchbadge/sqlx) for migrations
55+
3756
## Docs
3857

3958
If you chose to include docs then additional dev packages will be included for docs.
@@ -52,6 +71,12 @@ Install with `cargo`:
5271
cargo install python-project-generator
5372
```
5473

74+
If you want to be able to generate FastAPI projects install with the fastapi feature
75+
76+
```sh
77+
cargo install python-project-generator -F fastapi
78+
```
79+
5580
Install on Arch with the AUR:
5681

5782
```sh
@@ -118,13 +143,15 @@ python-project create -s
118143
- Application or Library
119144

120145
Choosing application will create `main.py` and `__main__.py` files. Choosing library will omit
121-
these files.
146+
these files. FastAPI projects are automatically created as applications with a special FastAPI
147+
main.py
122148

123149
- Async Project
124150

125151
Selecting yes for this option will add [pytest-asyncio](https://github.com/pytest-dev/pytest-asyncio)
126152
to the dev dependencies. Additionally if the project is an application the `main` function will
127-
be made async.
153+
be made async. This question is skipped with FastAPI projects and automatically set to an async
154+
project
128155

129156
- Max Line Length
130157

@@ -147,6 +174,9 @@ python-project create -s
147174
[trusted publisher](https://docs.pypi.org/trusted-publishers/adding-a-publisher/) in PyPI with
148175
a workflow name of pypi_publish.yml.
149176

177+
If the project is a FastAPI project this will create workflows to deploy to test and production
178+
servers using GitHub runners.
179+
150180
- Release Drafter
151181

152182
Choosing yes will create a [release drafter](https://github.com/release-drafter/release-drafter)
@@ -163,6 +193,9 @@ python-project create -s
163193
Choosing yes will setup CI to run tests on Linux, Mac, and Windows. If no is chosen tests will
164194
only run on Linux in CI.
165195

196+
This is skipped for FastAPI projects and defaults to Linux only. FastAPI projects use Docker
197+
with is only available in Linux in GitHub Actions.
198+
166199
- Include Docs
167200

168201
Choosing yes will add additional packages and base setup for creating documents with mkdocs.
@@ -271,6 +304,15 @@ Install the pre-commit hooks.
271304
pre-commit install
272305
```
273306

307+
### FastAPI projects
308+
309+
Create a .env file with the needed variables. the .env-example file can be used as a starter
310+
template. Then start the containers.
311+
312+
```sh
313+
docker compose up
314+
```
315+
274316
Now your project is ready to use.
275317

276318
### Save custom default values
@@ -368,6 +410,24 @@ fix any errors that fail. For example pre-commit can automatically apply changes
368410
fromatting. pre-commit caches information and only runs on files that have changed so it is fast
369411
and doesn't slow down your work flow will preventing you from forgetting to run checks.
370412

413+
### FastAPI migrations
414+
415+
[sqlx](https://github.com/launchbadge/sqlx) is used for migrations. A dedicated docker container
416+
runs the migrations each time docker is started. For creating new migrations install `sqlx-cli`.
417+
`sqlx-cli` also needs to be instealled in order to run the generated test suite.
418+
419+
```sh
420+
cargo install sqlx-cli --no-default-features --features native-tls,postgres
421+
```
422+
423+
Then to add a new migration run:
424+
425+
```sh
426+
sqlx migrate add -r my_migration
427+
```
428+
429+
This will create new migration up and down files in the migrations directory.
430+
371431
## Contributing
372432

373433
If you are interested in contributing please see our [contributing guide](CONTRIBUTING.md)

0 commit comments

Comments
 (0)