Skip to main content

Purpose of this package is to simplify interaction with 1C databases through COMobjects using Python language.

Project description

onecscripting

Purpose of this package is to simplify interaction with 1C databases through COMobjects using Python language. Access to database carried out by login and password and depends on your user's rights in that database.

The package:

  • contain techniques (methods) that can be used by an information security consultant working with RBAC.
  • allow you to make scripting/automation task to deal with 1C database.
  • work only for Windows OS.

Initial configuration:

  1. Install 1C client version 8.3 (supported versions >= 8.3.21.164).
  2. Register dll for you sepcific -version- (due to security policy might not be installed by default in step 1, see this):
regsvr32 "C:\Program Files\1cv8\-version-\bin\comcntr.dll"
  1. Setup your user in 1C database:
    • grant access rights to:
      • External Connection (StartExternalConnection);
      • (optional) read/write/e.t.c;
    • set authentification by login and password (domain/OS not allowed, only 1C: Enterprise);
    • additional for COM connection in control panel (top bar):
      • deselect Tools -> User Settings -> Request confirmation when closing the program (Сервис->Настройки пользователя->Запрашивать подтверждение при закрытии программы);
      • select Tools -> User Settings -> Prevent opening multiple sessions (Cервис->Настройки пользователя->Запретить открытие нескольких сеансов).

Usage

Initialization

from onecscripting.infobase import OneC


user: str = 'user'
password: str = 'password'
host: str = 'host'
database: str = 'database'

onec = OneC()

I'm assume that you aren't familiar with 1C API, that's why you should call onec = OneC() before connection to database. It's allow you to work with predefined class methods.

Sync conenction
with onec.connect(host=host, database=database, user=user, password=password):
    # do some stuff
    pass
Async connection
from typing import Dict, Any

from concurrent.futures import ThreadPoolExecutor, Future, as_completed


workers: int = 2  # number of threads
databases: Dict[str, str] = {
    'database1': 'host1',
    'database2': 'host2'
    }  # define databases parameters (let user and password be the same)

def job(system: OneC, **settings):
    with system.connect(**settings):
        # do some stuff in specific connection
        pass

# start async jobs
with ThreadPoolExecutor(max_workers=workers) as executor:
    jobs: Dict[Future, str] = {
        executor.submit(
            job,
            system=onec,
            host=host,
            database=database,
            user=user,
            password=password
            ): database for database, host in databases.items()
        }
    for future in as_completed(jobs):
        database: str = jobs[future]
        try:
            # get results of async jobs
            job_result: Any = future.result()
        except Exception as e:
            print('%s, %s' % (database, e))
        else:
            # do some stuff with job's result
            pass

Get all database users

from typing import List, Optional

from onecscripting.infobase import OneC
from onecscripting.dbobj import User


onec = OneC()
with onec.connect(
    host='host',
    database='database',
    user='user',
    password='password'
    ) as connection:
    infobase_users: List[Optional[User]] = connection.get_all_users()

Change password if it's expired

from onecscripting.infobase import OneC
from onecscripting.dbobj import User


onec = OneC()
with onec.connect(
    host='host',
    database='database',
    user='user',
    password='password'
    ) as connection:
    current_user: User = onec.current_user
    if current_user.password_is_expire(days_to_expire=30):
        current_user.change_password(password='new password')

For more information about usage please see additional examples in /tests dir and 1C examples tasks.

TODO:

  1. Implement PEP 249;
  2. Python standart async/await support;
  3. Check for password change applied.

LICENSE

MIT

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

onecscripting-1.0.1.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

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

onecscripting-1.0.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file onecscripting-1.0.1.tar.gz.

File metadata

  • Download URL: onecscripting-1.0.1.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.19

File hashes

Hashes for onecscripting-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e1817faaec5a05a5ec8c422b16d1e2f070b3c550c377b1da30b6ba2c4ed179f1
MD5 0a6426254c3abed68d0c23faba111dac
BLAKE2b-256 6db60025ddc1103e67204170286fb71c40113f05c8d0fbebc2759f4ccf1ffc52

See more details on using hashes here.

File details

Details for the file onecscripting-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: onecscripting-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.19

File hashes

Hashes for onecscripting-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6db4201e3445951290b220245519f2f2aeb5eb0cc6d46a111609846818531a42
MD5 829e980f20d8e63bcadefe8f9131e67b
BLAKE2b-256 78eb0369f64d7b9735bd37cc167686cc8c65c1636b4f9ab8eb7aae2fb1e00844

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