Skip to main content

Dependency Injection powered framework

Project description

Pyfony framework

Pyfony is a Dependency Injection (DI) powered framework written in Python greatly inspired by the Symfony Framework in PHP & Spring Framework in Java.

The DI functionality is provided by the Injecta Dependency Injection Container.

Pyfony = Injecta + bundles (extensions) API

Installation

$ pip install pyfony

Pyfony initialization

(The following steps are covered in the BaseKernelTest)

To start using Pyfony, create a simple config_dev.yaml file to define your DI services:

parameters:
  api:
    endpoint: 'https://api.mycompany.com'

services:
    mycompany.api.ApiClient:
      arguments:
        - '@mycompany.api.Authenticator'

    mycompany.api.Authenticator:
      class: mycompany.authenticator.RestAuthenticator
      arguments:
        - '%api.endpoint%'
        - '%env(API_TOKEN)%'

Then, initialize the container:

from injecta.config.YamlConfigReader import YamlConfigReader
from pyfony.kernel.BaseKernel import BaseKernel

appEnv = 'dev'

kernel = BaseKernel(
    appEnv,
    '/config/dir/path', # must be directory, not the config_dev.yaml file path!
    YamlConfigReader()
)

container = kernel.initContainer()

Use container.get() to finally retrieve your service:

from mycompany.api.ApiClient import ApiClient

apiClient = container.get('mycompany.api.ApiClient') # type: ApiClient   
apiClient.get('/foo/bar')

Advanced examples

  1. Advanced services configuration using Injecta
  2. Extending Pyfony with bundles

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pyfony-0.6.1-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

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