Skip to main content

Get companies info by using INPI api.

Project description

Django INPI

Django INPI allows you to use the INPI API to to get information about companies.

Features

  • Siren/Siret fields (django_inpi.fields.SIRETField, django_inpi.fields.SIRENField) which ensure that submitted Siren/Siret are numbers, and that their lenght is respectively 14 & 9 chars.
  • Forms with those custom fields (django_inpi.forms.SIRETForm, django_inpi.forms.SIRENForm)
  • An API (django_inpi.api.INPIApi) which allows you to get a token and make your own requests to the INSE API. Available functions:
    • login(): send a login POST request to INPI API, stores the Bearer token in your api instance (automatically called in INPIApi.__init__(), call INPIApi(skip_init=True) to skip login (if so, you will not have a token, and will need to login yourself)).
    • get(siret=None, siren=None): get company details using it's siret/siren. Returns the whole json from INPI API.
    • get_generic_company_data(siret=None, siren=None): get company details using it's siret/siren. Returns a formatted json containing only a few values (see examples below).
  • 4 Mixins that you can use in your views:
    • django_inpi.views.SIRETFormGetAllJsonMixin: Uses SIRETForm, and calls INPIApi.get(siret).
    • django_inpi.views.SIRETFormGetGenericCompanyDataMixin Uses SIRETForm, and calls INPIApi.get_generic_company_data(siret).
    • django_inpi.views.SIRENFormGetAllJsonMixin: Uses SIRENForm, and calls INPIApi.get(siren).
    • django_inpi.views.SIRENFormGetGenericCompanyDataMixin Uses SIRENForm, and calls INPIApi.get_generic_company_data(siren).

Install

  1. Install the package:
    python3 -m pip install django-inpi
    
  2. Add those apps to your INSTALLED_APPS:
    "django_inpi",
    
  3. Add your user/pass in your env vars & project settings:
    DJANGO_INPI_USERNAME = "username"
    DJANGO_INPI_PASSWORD = "username"
    
    from os import getenv
    
    DJANGO_INPI_USERNAME = getenv("DJANGO_INPI_USERNAME", None)
    DJANGO_INPI_PASSWORD = getenv("DJANGO_INPI_PASSWORD", None)
    
  4. That's all folks!

Examples

View

# my_app/urls.py

urlpatterns = [
    # ...
    path(
        "get-company-infos-from-siret/",
        views.GetCompanyInfosView.as_view(),
        name="get_company_infos",
    ),
]
# my_app/views.py
from django_inpi.views import SIRENFormGetAllJsonMixin

# ...
class GetCompanyInfosView(
    SIRENFormGetAllJsonMixin,  # <-- our mixin here
    FormView,  # required, our mixin does not inherit from any *View
):
    def get_success_url(self):
        return reverse(
            "my_app:get_company_infos",
        )

API

This package comes with an API that you can use independently from the Field or Form. Here's how to use it:

from django_inpi.api import INPIApi

inpi_api = INPIApi()
# use `inpi_api = INPIApi(skip_init=True)` if you want to call the login function yourself

# Get full json
siret = "01234567891234"
company_infos = inpi_api.get(siret=siret)
# OR
siren = "123456789"
company_infos = inpi_api.get(siren=siren)
from django_inpi.api import INPIApi

inpi_api = INPIApi()

# Get partial json
siret = "01234567891234"
generic_company_infos = inpi_api.get_generic_company_data(siret=siret)
# OR
siren = "123456789"
generic_company_infos = inpi_api.get_generic_company_data(siren=siren)

generic_company_infos wil contains those data:

{
  "siren": 123456789,
  "data": {
    "name": "NAME",
    "legal_status": {
      "full_name": "Full legal status name",
      "acronym": "FLSN"
    },
    "address": {
      "street_number": "1",
      "street_type": "STREET TYPE",
      "street_name": "STREET NAME",
      "postal_code": "01234",
      "city": "CITY NAME",
      "full_address": "1 STREET TYPE STREET NAME 01234 CITY NAME"
    },
    "manager": {
      "first_name": "MANAGER FIRST NAME",
      "last_name": "MANAGER LAST NAME"
    },
    "message": ""
  }
}

The "message" entry is filled only when there's an error, and it will contains debug infos (stack trace, or custom error message).

Config

  • DJANGO_INPI_USERNAME (no default, required): You must set this value in your settings in order to be able to access the INPI API.
  • DJANGO_INPI_PASSWORD (no default, required): You must set this value in your settings in order to be able to access the INPI API.

You must have an account on the INPI website in order to set your credentials, see here for registering a new account or here to login.

  • DJANGO_INPI_LOGIN_URL (default https://registre-national-entreprises.inpi.fr/api/sso/login): Set this var in your settings if you want to use a custom (selfhosted?) api.

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

django_inpi-0.0.2.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

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

django_inpi-0.0.2-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file django_inpi-0.0.2.tar.gz.

File metadata

  • Download URL: django_inpi-0.0.2.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.8.10 Linux/6.8.0-52-generic

File hashes

Hashes for django_inpi-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a6bcb28e232e6e43052ec9680288258eba22272e35440f0c4f0ae8ed699e7010
MD5 3f9b58fcdde615af673bae46daacd498
BLAKE2b-256 a8d11d4eaaf9ee3e8c60a610885ee76a6aca7454e881ffe69ac8e9fa795ed08b

See more details on using hashes here.

File details

Details for the file django_inpi-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: django_inpi-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 28.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.8.10 Linux/6.8.0-52-generic

File hashes

Hashes for django_inpi-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 aa2223dbfb0dc88ab9aa3a7acd3a99f02fdd330961d878edd72b4acf03db4df1
MD5 de0971263a8520d39f534a1a83be5950
BLAKE2b-256 a74572373fa8a3174501f537b84db1b1a75a0338a7cbcfda86be068f0488dced

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