55
66Generates a Python project structure with github actions for continuous integration and continuous
77deployment. 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
3958If you chose to include docs then additional dev packages will be included for docs.
@@ -52,6 +71,12 @@ Install with `cargo`:
5271cargo 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+
5580Install 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.
271304pre-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+
274316Now 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
368410fromatting. pre-commit caches information and only runs on files that have changed so it is fast
369411and 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
373433If you are interested in contributing please see our [ contributing guide] ( CONTRIBUTING.md )
0 commit comments