Skip to main content

PyNest is a FastAPI Abstraction for building microservices, influenced by NestJS.

Project description

PyNest is a Python framework built on top of FastAPI that follows the modular architecture of NestJS

Version Python Downloads License

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.

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:

pip install pynest-api

Start with cli

pynest generate application -n my_app_name

this command will create a new project with the following structure:

├── app.py
├── main.py
├── requirements.txt
├── .gitignore
├── README.md
├── src
│    ├── __init__.py

once you have created your app, get into the folder and run the following command:

cd my_app_name

run the server with the following command:

uvicorn "app:app" --host "0.0.0.0" --port "8000" --reload

Now you can visit OpenAPI in your browser to see the default API documentation.

Adding resources

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

pynest generate resource -n users

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

├── users
│    ├── __init__.py
│    ├── users_controller.py
│    ├── users_service.py
│    ├── users_model.py
│    ├── users_entity.py
│    ├── users_module.py

The users module will immediately register itself with the application and will be available for use.

You can then start defining routes and other application components using decorators and other PyNest constructs.

For more information on how to use PyNest, check out the official documentation at https://pythonnest.github.io/PyNest/.

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:

pynest Command

  • Description: The main command group for PyNest CLI.

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).

generate command group

  • Description: Group command for generating boilerplate code.

resource Subcommand

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

CLI Examples

  • create a blank nest application - pynest generate application -n my_app_name

  • 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.

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.

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.

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.

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.

Future Plans

  • 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 (Litestar, blackship, etc.) - Same Architecture, different engine.

Contributing

Contributions are welcome! Please feel free to grab one of the open issues, or open a new one if you have an idea for a new feature or improvement.

This would bring a huge impact to the project and the community.

License

PyNest is MIT licensed.

Credits

PyNest is inspired by NestJS.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pynest_api-0.4.0.tar.gz (33.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pynest_api-0.4.0-py3-none-any.whl (52.1 kB view details)

Uploaded Python 3

File details

Details for the file pynest_api-0.4.0.tar.gz.

File metadata

  • Download URL: pynest_api-0.4.0.tar.gz
  • Upload date:
  • Size: 33.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.10.18 Linux/6.11.0-1015-azure

File hashes

Hashes for pynest_api-0.4.0.tar.gz
Algorithm Hash digest
SHA256 4ff87df88250b09579b23f380e8ed3eaf974ccb7a84da7c859e8f0720bc4cdbc
MD5 c448c21a609dafcabc3c6d2e81867a35
BLAKE2b-256 dda2d7b315ca52aaa8d2a3024aa8c2f468bfdb0c035970d684d6fd698031c385

See more details on using hashes here.

File details

Details for the file pynest_api-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: pynest_api-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 52.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.10.18 Linux/6.11.0-1015-azure

File hashes

Hashes for pynest_api-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa5f568797cee5502793c4d251b107bcb906dc5ed57c2a5bdc6c0772ada22b59
MD5 db5eb754f9191016d6e3597b69295dca
BLAKE2b-256 0d8028b112f61beb7c2cf1d28bc76c7b30d35c5416d3158f31293138c685e61d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page