Skip to content

Commit

Permalink
(feat) build cli apps with pynest (#73)
Browse files Browse the repository at this point in the history
* add echo as an extra param to allow disabling logs from db

* (feat): add cli application building support using pynest structure

* (fix): ModuleNotFoundError: No module named 'nest.cli.cli'

* (fix): ModuleNotFoundError: No module named 'nest.cli.cli'

* (fix): ModuleNotFoundError: No module named 'nest.cli.cli'

* (fix): ModuleNotFoundError: No module named 'nest.cli.cli'

* (fix): ModuleNotFoundError: No module named 'nest.cli.cli'

* (fix): ModuleNotFoundError: No module named 'nest.cli.cli'

* (fix): ModuleNotFoundError: No module named 'nest.cli.cli'

* (fix): ModuleNotFoundError: No module named 'nest.cli.cli'

* (fix): ModuleNotFoundError: No module named 'nest.cli.cli'

* add support in async cli commands

* (format): run black

* remove aliases.py file
  • Loading branch information
itay-dar-lmnd committed Aug 6, 2024
1 parent 713a00e commit 6aa060a
Show file tree
Hide file tree
Showing 58 changed files with 1,247 additions and 244 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/cli_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,33 @@ jobs:
app_name="${{ matrix.app_type }}App"
case "${{ matrix.app_type }}" in
"Blank")
pynest create-nest-app -n "$app_name"
pynest generate application -n "$app_name"
;;
"SyncORM")
pynest create-nest-app -n "$app_name" -db sqlite
pynest generate application -n "$app_name" -db sqlite
;;
"AsyncORM")
pynest create-nest-app -n "$app_name" -db sqlite --is-async
pynest generate application -n "$app_name" -db sqlite --is-async
;;
"MongoDB")
pynest create-nest-app -n "$app_name" -db mongodb
pynest generate application -n "$app_name" -db mongodb
;;
"PostgresSync")
pynest create-nest-app -n "$app_name" -db postgresql
pynest generate application -n "$app_name" -db postgresql
;;
"PostgresAsync")
pynest create-nest-app -n "$app_name" -db postgresql --is-async
pynest generate application -n "$app_name" -db postgresql --is-async
;;
"MySQLSync")
pynest create-nest-app -n "$app_name" -db mysql
pynest generate application -n "$app_name" -db mysql
;;
"MySQLAsync")
pynest create-nest-app -n "$app_name" -db mysql --is-async
pynest generate application -n "$app_name" -db mysql --is-async
;;
esac
cd "$app_name"
pynest g module -n user
pynest generate resource -n user
- name: Verify Boilerplate
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ jobs:
fi
if [ "${{ matrix.app_type }}" == "Blank" ]; then
pynest create-nest-app -n "$app_name"
pynest generate application -n "$app_name"
else
pynest create-nest-app -n "$app_name" -db sqlite $is_async
pynest generate application -n "$app_name" -db sqlite $is_async
pip install aiosqlite
fi
cd "$app_name"
pynest g module -n user
pynest generate resource -n user
uvicorn "src.app_module:http_server" --host "0.0.0.0" --port 8000 --reload &
- name: Wait for the server to start
Expand Down
71 changes: 41 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,29 @@
</a>
</p>


# Description

PyNest is designed to help structure your APIs in an intuitive, easy to understand, and enjoyable way.

With PyNest, you can build scalable and maintainable APIs with ease. The framework supports dependency injection, type annotations, decorators, and code generation, making it easy to write clean and testable code.
With PyNest, you can build scalable and maintainable APIs with ease. The framework supports dependency injection, type
annotations, decorators, and code generation, making it easy to write clean and testable code.

This framework is not a direct port of NestJS to Python but rather a re-imagining of the framework specifically for Python developers, including backend engineers and ML engineers. It aims to assist them in building better and faster APIs for their data applications.
This framework is not a direct port of NestJS to Python but rather a re-imagining of the framework specifically for
Python developers, including backend engineers and ML engineers. It aims to assist them in building better and faster
APIs for their data applications.

## Getting Started

To get started with PyNest, you'll need to install it using pip:

```bash
pip install pynest-api
```

### Start with cli

```bash
pynest create-nest-app -n my_app_name
pynest generate appplication -n my_app_name
```

this command will create a new project with the following structure:
Expand Down Expand Up @@ -66,15 +70,16 @@ uvicorn "app:app" --host "0.0.0.0" --port "8000" --reload

Now you can visit [OpenAPI](http://localhost:8000/docs) in your browser to see the default API documentation.

### Adding modules
### Adding resources

To add a new module to your application, you can use the pynest generate module command:

```bash
pynest g module -n users
pynest generate resource -n users
```

This will create a new module called ```users``` in your application with the following structure under the ```src``` folder:
This will create a new resource called ```users``` in your application with the following structure under the ```src```
folder:

```text
├── users
Expand All @@ -94,72 +99,78 @@ For more information on how to use PyNest, check out the official documentation

## PyNest CLI Usage Guide

This document provides a guide on how to use the PyNest Command Line Interface (CLI). Below are the available commands and their descriptions:
This document provides a guide on how to use the PyNest Command Line Interface (CLI). Below are the available commands
and their descriptions:

### `pynest` Command

- **Description**: The main command group for PyNest CLI.

#### `create-nest-app` Subcommand
#### `generate application` Subcommand

- **Description**: Create a new nest app.
- **Options**:
- `--app-name`/`-n`: The name of the nest app (required).
- `--db-type`/`-db`: The type of the database (optional). You can specify PostgreSQL, MySQL, SQLite, or MongoDB.
- `--is-async`: Whether the project should be asynchronous (optional, default is False).
- `--app-name`/`-n`: The name of the nest app (required).
- `--db-type`/`-db`: The type of the database (optional). You can specify PostgreSQL, MySQL, SQLite, or MongoDB.
- `--is-async`: Whether the project should be asynchronous (optional, default is False).

### `g` command group
### `generate` command group

- **Description**: Group command for generating boilerplate code.

#### `module` Subcommand
#### `resource` Subcommand

- **Description**: Generate a new module (controller, service, entity, model, module).
- **Options**:
- `--name`/`-n`: The name of the module (required).

- `--name`/`-n`: The name of the module (required).

#### CLI Examples
* create a blank nest application -
`pynest create-nest-app -n my_app_name`

* create a nest application with postgres database and async connection -
`pynest create-nest-app -n my_app_name -db postgresql --is-async`
* create a blank nest application -
`pynest generate application -n my_app_name`

* create new module -
`pynest g module -n users`
* create a nest application with postgres database and async connection -
`pynest generate application -n my_app_name -db postgresql --is-async`

* create new module -
`pynest generate resource -n users`

## Key Features

### Modular Architecture

PyNest follows the modular architecture of NestJS, which allows for easy separation of concerns and code organization. Each module contains a collection of related controllers, services, and providers.
PyNest follows the modular architecture of NestJS, which allows for easy separation of concerns and code organization.
Each module contains a collection of related controllers, services, and providers.

### Dependency Injection
PyNest supports dependency injection, which makes it easy to manage dependencies and write testable code. You can easily inject services and providers into your controllers using decorators.

PyNest supports dependency injection, which makes it easy to manage dependencies and write testable code. You can easily
inject services and providers into your controllers using decorators.

### Decorators

PyNest makes extensive use of decorators to define routes, middleware, and other application components. This helps keep the code concise and easy to read.
PyNest makes extensive use of decorators to define routes, middleware, and other application components. This helps keep
the code concise and easy to read.

### Type Annotations

PyNest leverages Python's type annotations to provide better tooling and help prevent errors. You can annotate your controllers, services, and providers with types to make your code more robust.
PyNest leverages Python's type annotations to provide better tooling and help prevent errors. You can annotate your
controllers, services, and providers with types to make your code more robust.

### Code Generation

PyNest includes a code generation tool that can create boilerplate code for modules, controllers, and other components. This saves you time and helps you focus on writing the code that matters.
PyNest includes a code generation tool that can create boilerplate code for modules, controllers, and other components.
This saves you time and helps you focus on writing the code that matters.

## Future Plans

- [ ] Create plugins Marketplace for modules where developers can share their modules and download modules created by others.
- [ ] Create plugins Marketplace for modules where developers can share their modules and download modules created by
others.
- [ ] Implement IOC mechanism and introduce Module decorator
- [ ] Add support for new databases
- [ ] Create out-of-the-box authentication module that can be easily integrated into any application.
- [ ] Add support for other testing frameworks and create testing templates.
- [ ] Add support for other web frameworks (Flask, Django, etc.) - Same Architecture, different engine.

- [ ] Add support for other web frameworks (Litestar, blackship, etc.) - Same Architecture, different engine.

## Contributing

Expand Down
11 changes: 3 additions & 8 deletions docs/async_orm.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,8 @@ class AppModule:
pass


app = PyNestFactory.create(
AppModule,
description="This is my FastAPI app drive by Async ORM Engine",
title="My App",
version="1.0.0",
debug=True,
)
app = PyNestFactory.create(AppModule, description="This is my FastAPI app drive by Async ORM Engine", title="My App",
version="1.0.0", debug=True)

http_server = app.get_server()

Expand Down Expand Up @@ -383,4 +378,4 @@ uvicorn "src.app_module:http_server" --host "0.0.0.0" --port "8000" --reload
<a href="/PyNest/mongodb" class="md-footer-nav__link">
<span>Application Example With MongoDB &rarr;</span>
</a>
</nav>
</nav>
11 changes: 3 additions & 8 deletions docs/blank.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ from .app_controller import AppController
from .app_service import AppService
from fastapi import FastAPI


@Module(
controllers=[AppController],
providers=[AppService],
Expand All @@ -111,13 +112,7 @@ class AppModule:
pass


app = PyNestFactory.create(
AppModule,
description="This is my FastAPI app",
title="My App",
version="1.0.0",
debug=True,
)
app = PyNestFactory.create(AppModule, description="This is my FastAPI app", title="My App", version="1.0.0", debug=True)

http_server: FastAPI = app.get_server()
```
Expand Down Expand Up @@ -234,4 +229,4 @@ Now you can access the application at http://localhost:8000/docs and test the en
<a href="/PyNest/sync_orm" class="md-footer-nav__link">
<span>Application Example With ORM &rarr;</span>
</a>
</nav>
</nav>
Loading

0 comments on commit 6aa060a

Please sign in to comment.