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.


🚀 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 (with Poetry)

  1. Clone the repository:
git clone https://github.com/your-username/fmc_openapi.git
cd fmc_openapi
  1. Install dependencies:
poetry install
  1. (Optional) Activate the virtual environment:
poetry shell

🧑‍💻 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.0.tar.gz (18.4 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.0-py2.py3-none-any.whl (21.1 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

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

File hashes

Hashes for fmc_openapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5563eb559e300386243214d5c92051d41b3367057f9c05a0e3f5f206b4ad2f1a
MD5 ae176ac7dcbce3925fcf46e62701d33e
BLAKE2b-256 777bc3a40b4bfe85f80c5dbb98f369f49325c3f3427189b460f06038880edb88

See more details on using hashes here.

File details

Details for the file fmc_openapi-0.1.0-py2.py3-none-any.whl.

File metadata

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

File hashes

Hashes for fmc_openapi-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 12dc590eaa15b3ed5ac5bb6abfe571beaf462e58ad80fa3666510bf9a00654ae
MD5 a4d1869a8870c339fe033623b87b6f10
BLAKE2b-256 53478279a7a99dc106846381d1682b61dd153a359d12946fddfef2de361e36f9

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