Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

<!-- insertion marker -->
## [0.1.0](https://github.com/PythonNest/PyNest/releases/tag/0.1.0) - 2024-05-21
## [0.1.0](https://github.com/PythonNest/PyNest/releases/tag/0.1.0) - 2024-07-25

<small>[Compare with first commit](https://github.com/PythonNest/PyNest/compare/9ce6c1f09cd69cd2f5db55209425f9b0a343ccd4...0.1.0)</small>
<small>[Compare with first commit](https://github.com/PythonNest/PyNest/compare/4d239923eace38afdeae6515eb68b139ec506ca5...0.1.0)</small>

### Fixed
### Added

- Fix branch (#60) ([9ce6c1f](https://github.com/PythonNest/PyNest/commit/9ce6c1f09cd69cd2f5db55209425f9b0a343ccd4) by Itay Dar).
- add echo as an extra param to allow disabling logs from db (#71) ([4d23992](https://github.com/PythonNest/PyNest/commit/4d239923eace38afdeae6515eb68b139ec506ca5) by Itay Dar).

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
36 changes: 18 additions & 18 deletions docs/async_orm.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,27 @@ config = AsyncOrmProvider(
)
```

Note: you can add any parameters that needed in order to configure the database connection.
Disable asyncpg logging by set the parameter of `echo=False` in the `AsyncOrmProvider` object.
more on engine parameters [here](https://docs.sqlalchemy.org/en/20/core/engines.html)

`app_service.py`

```python
from nest.core import Injectable


@Injectable
class AppService:
def __init__(self):
self.app_name = "MongoApp"
self.app_name = "AsyncOrmApp"
self.app_version = "1.0.0"

async def get_app_info(self):
return {"app_name": self.app_name, "app_version": self.app_version}
```

`app_controller.py`

```python
from nest.core import Controller, Get

Expand Down Expand Up @@ -152,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 All @@ -168,8 +166,10 @@ async def startup():
await config.create_all()
```

`@Module(...)`: This is a decorator that defines a module. In PyNest, a module is a class annotated with a `@Module()` decorator.
The imports array includes the modules required by this module. In this case, ExampleModule is imported. The controllers and providers arrays are empty here, indicating this module doesn't directly provide any controllers or services.
`@Module(...)`: This is a decorator that defines a module. In PyNest, a module is a class annotated with a `@Module()`
decorator.
The imports array includes the modules required by this module. In this case, ExampleModule is imported. The controllers
and providers arrays are empty here, indicating this module doesn't directly provide any controllers or services.

`PyNestFactory.create()` is a command to create an instance of the application.
The AppModule is passed as an argument, which acts as the root module of the application.
Expand All @@ -189,8 +189,6 @@ other parameters for efficient database access.
AsyncSession from sqlalchemy.ext.asyncio is used for executing asynchronous database operations. It is essential for
leveraging the full capabilities of SQLAlchemy 2.0 in an async environment.



## Implementing Async Features

### Creating Entities
Expand Down Expand Up @@ -305,11 +303,12 @@ from sqlalchemy.ext.asyncio import AsyncSession

@Controller("examples")
class ExamplesController:
def __init__(self, service: ExamplesService):

def __init__(self, service: ExamplesService):
self.service = service

@Get("/")

async def get_examples(self, session: AsyncSession = Depends(config.get_db)):
return await self.service.get_examples(session)

Expand All @@ -330,11 +329,12 @@ from .examples_model import Examples

@Controller("examples")
class ExamplesController:
def __init__(self, service: ExamplesService):

def __init__(self, service: ExamplesService):
self.service = service

@Get("/")

async def get_examples(self):
return await self.service.get_examples()

Expand Down Expand Up @@ -378,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