Skip to main content

A simple Python client to interact with Cisco FMC or SCC APIs using operationId from the OpenAPI spec.

Project description

FMC OpenAPI

fmc_openapi is a Python package that simplifies interaction with Cisco Firepower Management Center (FMC) APIs. It dynamically parses the OpenAPI (Swagger) specification to discover available endpoints and interact with them using the operationId.

To identify which operations are supported, you can refer to the Operation ID table.


🚀 Features

  • 🔍 Parses the Swagger file to discover endpoints
  • 💡 Calls API operations by operationId
  • 🔐 Session handling (login/logout)
  • 🧰 Simplifies complex API interactions
  • ⚠️ Error handling built-in
  • 🏢 SCC/CDO Token-Based Authentication
  • 🔄 Automatic pagination handling (manual pagination is also possible)
  • 📦 Bulk operations
  • 📄 All endpoints defined in the Swagger spec

📦 Installation

pip install fmc_openapi

Import API client

from fmc_openapi import FMCOpenAPIClient

🧑‍💻 Usage Example

Connecting to FMC (username/password)

from fmc_openapi import FMCOpenAPIClient

with FMCOpenAPIClient(
    hostname="fmc.example.com",
    username="your_username",
    password="your_password",
    verify=False
) as fmc:
    domains = fmc.operation("getAllDomain")

Connecting to SCC (token-based)

from fmc_openapi import FMCOpenAPIClient

with FMCOpenAPIClient(
    hostname="scc.example.com",
    token="your_token_here",
    verify=False
) as fmc:
    domains = fmc.operation("getAllDomain")

Get all access policy rules

import jmespath

with FMCOpenAPIClient(
    hostname="fmc.example.com",
    username="your_username",
    password="your_password",
    verify=False
) as fmc:
    # Get domain UUID
    domains = fmc.operation("getAllDomain")
    domain_uuid = jmespath.search("items[?name=='my-domain'].uuid | [0]", domains)

    # Get ACP UUID
    acp_response = fmc.operation("getAllAccessPolicy", domainUUID=domain_uuid)
    acp_uuid = jmespath.search("items[?name=='my-policy'].uuid | [0]", acp_response)

    # Get all access policy rules (with automatic pagination)
    rules = fmc.operation(
        "getAllAccessRule", 
        limit=1000, 
        domainUUID=domain_uuid, 
        containerUUID=acp_uuid, 
        expanded=True
    )

Manual Pagination

rules = fmc.operation(
    "getAllAccessRule",
    limit=1000,
    domainUUID=domain_uuid,
    containerUUID=acp_uuid,
    expanded=True,
    manual_pagination=True
)

Creating Objects

payload = {
    "name": "obj-192.168.1.0",
    "type": "Network",
    "value": "192.168.1.0/24",
}

fmc.operation("createMultipleNetworkObject", payload=payload, domainUUID=domain_uuid)

Bulk Operations

response = fmc.operation(
    "getHitCount", 
    limit=1000, 
    domainUUID=domain_uuid, 
    containerUUID=ac_uuid_selected, 
    filter=f"deviceId:{device_uuid}", 
    expanded=True,
    bulk=True
)

🧪 Running Tests

Tests are written using pytest.

To run tests:

poetry run pytest

Or activate the environment first:

poetry shell
pytest

🛠 Project Structure

fmc_openapi/
├── __init__.py           # Imports FMCOpenAPIClient
├── client.py             # Main client class
├── swagger.py            # Swagger parser
├── utils.py              # Logging and request helpers
tests/
├── test_swagger.py       # Tests for Swagger JSON fetching and operation extraction
├── test_operation.py     # Tests for executing API operations using operationId
├── test_auth.py          # Tests for authentication: login and logout
├── test_client.py        # General client behavior and utility method tests

📄 License

GNU GPL v3 License. See LICENSE for details.


🤝 Contributing

Pull requests are welcome! If you plan to add new features, open an issue first to discuss it.

  1. Fork the project
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a pull request

✉️ Contact

Questions? Ideas? Open an issue or drop a message.

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

fmc_openapi-0.1.2.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

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

fmc_openapi-0.1.2-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file fmc_openapi-0.1.2.tar.gz.

File metadata

  • Download URL: fmc_openapi-0.1.2.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.9 Darwin/24.4.0

File hashes

Hashes for fmc_openapi-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d23c281cebf9478835f3ba88628a91e6b63cd34cb4ddc11acd3b7d7a88a40405
MD5 30fa995a7977eab1b66b75d3e4a2ae19
BLAKE2b-256 dd7f4f37726b3c7e272f0e8e36cc5e133fe2b1dccace1792fefa7d85330b52e6

See more details on using hashes here.

File details

Details for the file fmc_openapi-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: fmc_openapi-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.9 Darwin/24.4.0

File hashes

Hashes for fmc_openapi-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 38aefa8f0781b596ad34c9ecf9964ffe5f9318eb5f6f3ff13316343bed765e54
MD5 2924a95b18754f84a4ce78dc9cac7ef8
BLAKE2b-256 91da918eaa0b89ec1d850e39abfbd2790def73632e532fa7d60c67484bf3bd03

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