Skip to content

nirsimetri/onvif-python

ONVIF Python

License DeepWiki Release
PyPI Downloads

Are you having trouble finding a Python ONVIF library that supports your device?
Are you confused about the compatibility of the various ONVIF versions, which are updated every six months?

This project provides a comprehensive and developer-friendly Python library for working with ONVIF-compliant devices. It is designed to be reliable, easy to integrate, and flexible enough to support a wide range of ONVIF profiles and services.

ONVIF (Open Network Video Interface Forum) is a global standard for the interface of IP-based physical security products, including network cameras, video recorders, and related systems.

Behind the scenes, ONVIF communication relies on SOAP (Simple Object Access Protocol) — an XML-based messaging protocol with strict schema definitions (WSDL/XSD). SOAP ensures interoperability, but when used directly it can be verbose, complex, and error-prone.

This library simplifies that process by wrapping SOAP communication into a clean, Pythonic API. You no longer need to handle low-level XML parsing, namespaces, or security tokens manually — the library takes care of it, letting you focus on building functionality.

Key Features

  • Full implementation of ONVIF core services and profiles
  • Support for device discovery, media streaming, PTZ control, event management, and more
  • Pythonic abstraction over SOAP requests and responses (no need to handcraft XML)
  • Extensible architecture for custom ONVIF extensions
  • Compatible with multiple ONVIF specification versions
  • Example scripts and tests included

Who Is It For?

  • Individual developers exploring ONVIF or building hobby projects
  • Companies building video intelligence, analytics, or VMS platforms
  • Security integrators who need reliable ONVIF interoperability across devices

Installation

From official PyPI:

pip install onvif-python

Or clone this repository and install locally:

git clone https://github.com/nirsimetri/onvif-python
cd onvif-python
pip install .

Usage Example

Tip

You can view the complete documentation automatically generated by DeepWiki via the onvif-python AI Wiki link. We currently do not have an official documentation site. Help us create more examples and helpful documentation by contributing.

Below are simple examples to help you get started with the ONVIF Python library. These demonstrate how to connect to an ONVIF-compliant device and retrieve basic device information.

1. Initialize the ONVIFClient

Create an instance of ONVIFClient by providing your device's IP address, port, username, and password:

from onvif import ONVIFClient

client = ONVIFClient("192.168.1.17", 8000, "admin", "admin123")

2. Create Service Instance

ONVIFClient provides several main services that can be accessed via the following methods:

  • client.devicemgmt() — Device Management
  • client.events() — Events
  • client.imaging() — Imaging
  • client.media() — Media
  • client.ptz() — PTZ (Pan-Tilt-Zoom)
  • client.analytics() — Analytics

and so on, check Implemented ONVIF Services for more details

Example usage:

device = client.devicemgmt()      # Device Management (Core)
media = client.media()            # Media

3. Get Device Information

Retrieve basic information about the device, such as manufacturer, model, firmware version, and serial number using devicemgmt() service:

info = device.GetDeviceInformation()
print(info)
# Example output: {'Manufacturer': '...', 'Model': '...', 'FirmwareVersion': '...', 'SerialNumber': '...'}

4. Get RTSP URL

Retrieve the RTSP stream URL for live video streaming from the device using media() service:

profile = media.GetProfiles()[0]  # use the first profile
stream = media.GetStreamUri(
    ProfileToken=profile.token, 
	StreamSetup={"Stream": "RTP-Unicast", "Transport": {"Protocol": "RTSP"}}
)
print(stream)
# Example output: {'Uri': 'rtsp://192.168.1.17:8554/Streaming/Channels/101', ...}

Explore more advanced usage and service-specific operations in the examples/ folder.

Important

If you're new to ONVIF and want to learn more, we highly recommend taking the official free online course provided by ONVIF at Introduction to ONVIF Course. Please note that we are not endorsed or sponsored by ONVIF, see Legal Notice for details.

Device Verification: Why Use GetCapabilities First?

Warning

Before performing any operations on an ONVIF device, it is highly recommended to verify which capabilities and services are available and supported by the device using the GetCapabilities method from devicemgmt() service instance. This step ensures that your application interacts only with features that the device actually implements, preventing errors and improving compatibility.

Why verify device capabilities with GetCapabilities?

  • Device Diversity: Not all ONVIF devices support every capability or service. Capabilities may vary by manufacturer, model, firmware, or configuration.
  • Error Prevention: Attempting to use unsupported features can result in failed requests, exceptions, or undefined behavior.
  • Dynamic Feature Detection: Devices may enable or disable capabilities over time (e.g., after firmware updates or configuration changes).
  • Optimized Integration: By checking available capabilities, your application can adapt its workflow and UI to match the device's actual features.

How to verify device capabilities:

Call GetCapabilities on your devicemgmt() instance:

from onvif import ONVIFClient

client = ONVIFClient("192.168.1.17", 8000, "admin", "admin123")
capabilities = client.devicemgmt().GetCapabilities()
print(capabilities)
# Example output: {'Media': {'XAddr': 'http://192.168.1.17:8000/onvif/media_service', ...}, 'PTZ': {...}, ...}

Review the returned dictionary to determine which capabilities and services (e.g., Media, PTZ, Analytics) are available before invoking further operations.

Tested Devices

This library has been tested with a variety of ONVIF-compliant devices. For the latest and most complete list of devices that have been verified to work with this library, please refer to:

If your device is not listed right now, feel free to contribute your test results or feedback via Issues or Discussions at onvif-products-directory. Your contribution will be invaluable to the community and the public.

Important

Device testing contributions must be made with a real device and use the scripts provided in the onvif-products-directory repo. Please be sure to contribute using a device model not already listed.

Supported ONVIF Profiles

This library fully supports all major ONVIF Profiles listed below. Each profile represents a standardized set of features and use cases, ensuring interoperability between ONVIF-compliant devices and clients. You can use this library to integrate with devices and systems that implement any of these profiles.

Name Specifications Main Features Typical Use Case Support
Profile_S Document Video streaming, PTZ, audio, multicasting Network video transmitters (cameras) and receivers (recorders, VMS) ✅ Yes
Profile_G Document Recording, search, replay, video storage Video recorders, storage devices ✅ Yes
Profile_T Document Advanced video streaming (H.265, analytics metadata, motion detection) Modern cameras and clients ✅ Yes
Profile_C Document Access control, door monitoring Door controllers, access systems ✅ Yes
Profile_A Document Advanced access control configuration, credential management Access control clients and devices ✅ Yes
Profile_D Document Access control peripherals (locks, sensors, relays) Peripheral devices for access control ✅ Yes
Profile_M Document Metadata, analytics events, object detection Analytics devices, metadata clients ✅ Yes

For a full description of each profile and its features, visit ONVIF Profiles.

Implemented ONVIF Services

Note

For details about the available service functions and methods already implemented in this library, see the source code in onvif/services/. Or if you want to read in a more proper format visit onvif-python AI Wiki.

Below is a list of ONVIF services implemented and supported by this library, along with links to the official specifications, service definitions, and schema files as referenced from the ONVIF Developer Specs. This table provides a quick overview of the available ONVIF features and their technical documentation for integration and development purposes.

Service Specifications Service Definitions Schema Files Status
Device Management Document device.wsdl onvif.xsd
common.xsd
✅ Complete
Events Document event.wsdl onvif.xsd
common.xsd
⚠️ Partial
Access Control Document accesscontrol.wsdl types.xsd ✅ Complete
Access Rules Document accessrules.wsdl - ✅ Complete
Action Engine Document actionengine.wsdl - ✅ Complete
Analytics Document analytics.wsdl rules.xsd
humanbody.xsd
humanface.xsd
✅ Complete
Application Management Document appmgmt.wsdl - ✅ Complete
Authentication Behavior Document authenticationbehavior.wsdl - ✅ Complete
Cloud Integration Document cloudintegration.yaml - ❌ Not yet
Credential Document credential.wsdl - ✅ Complete
Device IO Document deviceio.wsdl - ✅ Complete
Display Document display.wsdl - ✅ Complete
Door Control Document doorcontrol.wsdl - ✅ Complete
Imaging Document imaging.wsdl - ✅ Complete
Media Document media.wsdl - ✅ Complete
Media 2 Document media2.wsdl - ✅ Complete
Provisioning Document provisioning.wsdl - ✅ Complete
PTZ Document ptz.wsdl - ✅ Complete
Receiver Document receiver.wsdl - ✅ Complete
Recording Control Document recording.wsdl - ✅ Complete
Recording Search Document search.wsdl - ✅ Complete
Replay Control Document replay.wsdl - ✅ Complete
Resource Query Document - ❌ Any idea?
Schedule Document schedule.wsdl - ✅ Complete
Security Document advancedsecurity.wsdl - ✅ Complete
Thermal Document thermal.wsdl radiometry.xsd ✅ Complete
Uplink Document uplink.wsdl - ✅ Complete
WebRTC Document - - ❌ Any idea?

Service Bindings in ONVIF

ONVIF services are defined by WSDL bindings. In this library, there are two main patterns:

1. Single Binding Services

Most ONVIF services use a single binding, mapping directly to one endpoint. These are accessed via simple client methods, and the binding/xAddr is always known from device capabilities.

Examples:
client.devicemgmt()   # DeviceBinding
client.media()        # MediaBinding
client.ptz()          # PTZBinding
...

✅ These are considered fixed and always accessed directly.

2. Multi-Binding Services

Some ONVIF services have multiple bindings in the same WSDL. These typically include:

  • A root binding (main entry point)
  • One or more sub-bindings, discovered or created dynamically (e.g. after subscription/configuration creation)
Examples:
  1. Events

    • Root: EventBinding
    • Sub-bindings:
      • PullPointSubscriptionBinding (created via CreatePullPointSubscription)
      • SubscriptionManagerBinding (manages existing subscriptions)
      • NotificationProducerBinding

    Usage in library:

    client.events()                    # root binding
    client.pullpoint(subscription)     # sub-binding (dynamic, via SubscriptionReference.Address)
    client.subscription(subscription)  # sub-binding (dynamic, via SubscriptionReference.Address)
  2. Security (Advanced Security)

    • Root: AdvancedSecurityServiceBinding
    • Sub-bindings:
      • AuthorizationServerBinding
      • KeystoreBinding
      • CredentialBinding
      • JWTBinding
      • Dot1XBinding
      • TLSServerBinding
      • MediaSigningBinding

    Usage in library:

    client.security()                  # root binding
    client.authorizationserver(xaddr)  # sub-binding accessor (requires xAddr)
    client.keystore(xaddr)
    client.jwt(xaddr)
    client.dot1x(xaddr)
    client.tlsserver(xaddr)
    client.mediasigning(xaddr)
  3. Analytics

    • Root: AnalyticsEngineBinding
    • Sub-bindings:
      • RuleEngineBinding

    Usage in library:

    client.analytics()   # root binding
    client.ruleengine()  # sub-binding accessor

Summary

  • Single binding services: Always accessed directly (e.g. client.media()).
  • Multi-binding services: Have a root + sub-binding(s). Root is fixed; sub-bindings may require dynamic creation or explicit xAddr (e.g. client.pullpoint(subscription), client.authorizationserver(xaddr)).

Future Improvements (Stay tuned and star ⭐ this repo)

  • Implement structured data models for ONVIF Schemas using xsdata.
  • Integrate xmltodict for simplified XML parsing and conversion.
  • Add functionality for ONVIFClient to accept a custom wsdl_path service.
  • Enhance documentation with API references and diagrams (not from AI Wiki).
  • Add more usage examples for advanced features.
  • Add benchmarking and performance metrics.
  • Add community-contributed device configuration templates.
  • Implement missing or partial ONVIF services.
  • Add function to expose ONVIF devices (for debugging purposes by the community).

Related Projects

  • onvif-products-directory: This project is a comprehensive ONVIF data aggregation and management suite, designed to help developers explore, analyze, and process ONVIF-compliant product information from hundreds of manufacturers worldwide. It provides a unified structure for device, client, and company data, making it easier to perform research, build integrations, and generate statistics for ONVIF ecosystem analysis.

  • (soon) onvif-rest-server: A RESTful API server for ONVIF devices, enabling easy integration of ONVIF device management, media streaming, and other capabilities into web applications and services.

  • (soon) onvif-mcp: A Model Context Protocol (MCP) server for ONVIF, providing a unified API and context-based integration for ONVIF devices, clients, and services. It enables advanced automation, orchestration, and interoperability across ONVIF-compliant devices and clients.

Alternatives

If you are looking for other ONVIF Python libraries, here are some alternatives:

  • python-onvif-zeep: A synchronous ONVIF client library for Python, using Zeep for SOAP communication. Focuses on compatibility and ease of use for standard ONVIF device operations. Good for scripts and applications where async is not required.

  • python-onvif-zeep-async: An asynchronous ONVIF client library for Python, based on Zeep and asyncio. Suitable for applications requiring non-blocking operations and concurrent device communication. Supports many ONVIF services and is actively maintained.

References

Legal Notice

This project is an independent open-source implementation of the ONVIF specifications. It is not affiliated with, endorsed by, or sponsored by ONVIF or its member companies.

  • The name “ONVIF” and the ONVIF logo are registered trademarks of the ONVIF organization.
  • Any references to ONVIF within this project are made strictly for the purpose of describing interoperability with ONVIF-compliant devices and services.
  • Use of the ONVIF trademark in this repository is solely nominative and does not imply any partnership, certification, or official status.
  • This project includes WSDL/XSD/HTML files from the official ONVIF specifications.
  • These files are © ONVIF and are redistributed here for interoperability purposes.
  • All rights to the ONVIF specifications are reserved by ONVIF.

If you require certified ONVIF-compliant devices or clients, please refer to the official ONVIF conformant product list. For authoritative reference and the latest official ONVIF specifications, please consult the ONVIF Official Specifications.

Use of this library is at your own risk. The authors and contributors assume no liability for any damages, direct or indirect, arising from its use.

License

This project is licensed under the MIT License. See LICENSE for details.

About

A comprehensive and developer-friendly Python library for working with ONVIF-compliant devices

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages