### Project Setup with uv Source: https://github.com/nokia/network-as-code-py/blob/main/CONTRIBUTING.md Provides the command to synchronize project dependencies using uv. This is a crucial step for first-time setup and ensuring the development environment is correctly configured. ```bash uv sync ``` -------------------------------- ### Install Network as Code Python SDK Source: https://github.com/nokia/network-as-code-py/blob/main/README.md Installs the Network as Code Python library using pip. This is the primary method for acquiring the SDK for use in Python projects. ```bash pip install network_as_code ``` -------------------------------- ### Model Object Interactions in Python Source: https://github.com/nokia/network-as-code-py/blob/main/CONTRIBUTING.md Illustrates how Model objects in the SDK represent network resources and can perform actions. This includes retrieving a device, creating a QoDSession associated with it, and clearing sessions. ```python device = client.devices.get(...) session = device.create_qod_session(...) device.clear_sessions() ``` -------------------------------- ### Using Namespaces in NetworkAsCodeClient Source: https://github.com/nokia/network-as-code-py/blob/main/CONTRIBUTING.md Demonstrates how to access and use namespaces within the NetworkAsCodeClient object. Namespaces group related functions and interact with API bindings to manage Network as Code resources. ```python client = NetworkAsCodeClient(...) client..(...) ``` -------------------------------- ### Get Device Information in Python Source: https://context7.com/nokia/network-as-code-py/llms.txt Retrieves device objects using various identifiers such as phone number, network access identifier, or IP addresses. This function supports querying devices with multiple identification methods. ```python from network_as_code.models.device import DeviceIpv4Addr # Simple device with phone number only device = client.devices.get(phone_number="+3637123456") # Device with multiple identifiers device = client.devices.get( network_access_identifier="device@testcsp.net", ipv4_address=DeviceIpv4Addr( public_address="233.252.0.2", private_address="192.0.2.25", public_port=80 ), ipv6_address="2001:db8:1234:5678:9abc:def0:fedc:ba98", phone_number="+3672123456" ) ``` -------------------------------- ### Device Swap Detection (Python) Source: https://context7.com/nokia/network-as-code-py/llms.txt Detects physical device changes for a phone number. Includes functions to get the last device swap date, verify any device swap, and verify swaps within a specific age (e.g., last 24 hours). ```python # Get last device swap date device_swap_date = device.get_device_swap_date() if device_swap_date: print(f"Device swap: {device_swap_date.isoformat()}") # Verify device swap if device.verify_device_swap(): print("Device swap detected") # Check for device swap within 24 hours if device.verify_device_swap(max_age=24): print("Recent device swap in last 24 hours") ``` -------------------------------- ### Get and Verify Device Location in Python Source: https://context7.com/nokia/network-as-code-py/llms.txt Retrieves the current location of a device and verifies if the device is within a specified geographical area. It handles location data including longitude, latitude, and radius, with options for maximum age of location data. ```python # Get device location (default max_age=60 seconds) location = device.location(max_age=60) print(f"Longitude: {location.longitude}") print(f"Latitude: {location.latitude}") print(f"Radius: {location.radius}") # Verify if device is within specified area verification = device.verify_location( longitude=19.0, latitude=47.0, radius=10000, # 10km radius in meters max_age=3600 ) print(f"Location verified: {verification.result_type}") print(f"Match rate: {verification.match_rate}") print(f"Last location time: {verification.last_location_time}") ``` -------------------------------- ### Initialize NetworkAsCodeClient in Python Source: https://context7.com/nokia/network-as-code-py/llms.txt Initializes the NetworkAsCodeClient using an API token obtained from the Nokia developer portal. This client is the main entry point for all SDK operations. ```python import network_as_code as nac client = nac.NetworkAsCodeClient(token="your_api_token_here") ``` -------------------------------- ### Manage QoS Sessions in Python Source: https://context7.com/nokia/network-as-code-py/llms.txt Creates, retrieves, lists, and deletes Quality of Service (QoS) sessions for guaranteed bandwidth. Sessions can be configured with specific IP addresses, QoS profiles, durations, and notification URLs. It also shows how to access session details and clear all sessions for a device. ```python # Create QoS session with QOS_L profile for 1 hour session = device.create_qod_session( service_ipv4="233.252.0.2", service_ipv6="2001:db8:1234:5678:9abc:def0:fedc:ba98", profile="QOS_L", duration=3600, notification_url="https://example.com/notifications", notification_auth_token="c8974e592c2fa383d4a3960714" ) # Access session details print(session.id) print(session.duration) print(session.started_at) print(session.expires_at) # List all sessions for a device all_sessions = device.sessions() # Get specific session by ID session = client.sessions.get(session.id) # Delete session session.delete() # Delete all sessions for a device device.clear_sessions() ``` -------------------------------- ### Initialize NetworkAsCodeClient with API Token Source: https://github.com/nokia/network-as-code-py/blob/main/README.md Initializes the NetworkAsCodeClient using an API token. This client is essential for authenticating and interacting with the Network as Code platform's APIs. ```python import network_as_code as nac client = nac.NetworkAsCodeClient( token="", ) ``` -------------------------------- ### Manage 5G Network Slices with Python Source: https://context7.com/nokia/network-as-code-py/llms.txt This snippet demonstrates how to create, activate, attach devices to, detach devices from, deactivate, and delete 5G network slices using the Python SDK. It includes waiting for state changes and configuring QoS and traffic categories. Dependencies include the network_as_code library. ```python import asyncio from network_as_code.models.slice import ( Point, AreaOfService, NetworkIdentifier, SliceInfo, Throughput, TrafficCategories, Apps ) from network_as_code.models.device import DeviceIpv4Addr async def manage_slice(): # Create network slice my_slice = client.slices.create( name="slice-test-xyzzy", network_id=NetworkIdentifier(mcc="236", mnc="30"), slice_info=SliceInfo(service_type="eMBB", differentiator="444444"), area_of_service=AreaOfService(polygon=[ Point(latitude=47.344, longitude=104.349), Point(latitude=35.344, longitude=76.619), Point(latitude=12.344, longitude=142.541), Point(latitude=19.43, longitude=103.53) ]), slice_downlink_throughput=Throughput(guaranteed=3415, maximum=1234324), slice_uplink_throughput=Throughput(guaranteed=3415, maximum=1234324), device_downlink_throughput=Throughput(guaranteed=3415, maximum=1234324), device_uplink_throughput=Throughput(guaranteed=3415, maximum=1234324), max_data_connections=10, max_devices=6, notification_url="https://example.com/notifications" ) print(f"Slice created: {my_slice.sid}") # Wait for slice to become available await my_slice.wait_for(desired_state="AVAILABLE") # Activate slice my_slice.activate() await my_slice.wait_for(desired_state="OPERATING") # Attach device to slice device = client.devices.get( phone_number="+3670123456", ipv4_address=DeviceIpv4Addr(public_address="1.1.1.2", public_port=54000) ) my_slice.attach( device, traffic_categories=TrafficCategories( apps=Apps( os="97a498e3-fc92-5c94-8986-0333d06e4e47", apps=["ENTERPRISE"] ) ), notification_url="https://example.com/notifications", notification_auth_token="c8974e592c2fa383d4a3960714" ) # Detach device my_slice.detach(device) # Deactivate and delete slice my_slice.deactivate() await my_slice.wait_for(desired_state="AVAILABLE") my_slice.delete() asyncio.run(manage_slice()) # Retrieve existing slice slice = client.slices.get("slice-test-xyzzy") # List all slices all_slices = client.slices.get_all() ``` -------------------------------- ### Subscribe to Geofencing Events with Python Source: https://context7.com/nokia/network-as-code-py/llms.txt This snippet shows how to create a geofencing subscription to receive notifications when a device enters or leaves a specified circular area. It configures the subscription with event types, area, sink URL, credential, expiration time, and maximum events. Dependencies include the network_as_code library and datetime objects. ```python from datetime import datetime, timedelta, timezone from network_as_code.models.geofencing import ( Circle, EventType, PlainCredential ) # Create geofencing subscription subscription = client.geofencing.subscribe( device=device, sink="https://example.com/geofence-notifications", types=[EventType.AREA_ENTERED, EventType.AREA_LEFT], area=Circle( latitude=47.344, longitude=104.349, radius=5000 # 5km radius in meters ), sink_credential=PlainCredential( credential_type="PLAIN", credential="my-auth-token" ), subscription_expire_time=datetime.now(timezone.utc) + timedelta(days=7), subscription_max_events=100, initial_event=True ) print(f"Geofencing subscription: {subscription.id}") # Retrieve subscription sub = client.geofencing.get(subscription.id) # List all geofencing subscriptions all_subs = client.geofencing.get_all() # Delete subscription subscription.delete() ``` -------------------------------- ### Network Congestion Subscription (Python) Source: https://context7.com/nokia/network-as-code-py/llms.txt Subscribes to network congestion notifications and retrieves congestion data for a specified time range. Requires setting expiration time, notification URL, and authentication token for subscriptions. ```python from datetime import datetime, timezone, timedelta # Subscribe to congestion notifications congestion_subscription = client.insights.subscribe_to_congestion_info( device, subscription_expire_time=datetime.now(timezone.utc) + timedelta(days=1), notification_url="https://example.com/notify", notification_auth_token="my-secret-token" ) print(f"Subscription ID: {congestion_subscription.id}") print(f"Starts: {congestion_subscription.starts_at}") print(f"Expires: {congestion_subscription.expires_at}") # Get congestion data for time range congestion_levels = device.get_congestion( start=datetime.now(timezone.utc), end=datetime.now(timezone.utc) + timedelta(hours=3) ) for level in congestion_levels: print(f"Time: {level.timestamp}, Level: {level.level}") ``` -------------------------------- ### Number Verification Flow (Python/FastAPI) Source: https://context7.com/nokia/network-as-code-py/llms.txt Demonstrates the OAuth2 authorization flow for verifying device phone numbers. It covers creating an authentication link, setting up a FastAPI endpoint to receive the authorization code, and using the code to verify the number and retrieve the phone number. ```python from fastapi import FastAPI # Create authorization link for user to authenticate callback = client.authorization.create_authentication_link( redirect_uri="https://my-example.com/redirect", login_hint=device.phone_number, scope="number-verification:verify", state="foobar" # CSRF protection token ) # User clicks link and is redirected to your endpoint with authorization code # FastAPI endpoint to receive authorization code app = FastAPI() @app.get("/redirect") async def get_authorization_code(code: str, state: str = None): # Verify state matches to prevent CSRF attacks if state != "foobar": return {"error": "Invalid state"}, 401 return {"code": code} # Use authorization code to verify phone number authorization_code = "NaC-authorization-code" is_verified = device.verify_number(code=authorization_code) print(f"Number verified: {is_verified}") # Retrieve device phone number (requires different scope) phone_number = device.get_phone_number(code=authorization_code) print(f"Device phone: {phone_number}") ``` -------------------------------- ### Detect SIM Swaps in Python Source: https://context7.com/nokia/network-as-code-py/llms.txt Provides functionality to detect SIM card swaps for fraud prevention. It allows retrieving the last SIM swap date and verifying if any SIM swap has occurred for a device. ```python from datetime import datetime # Get last SIM swap date (returns None if no swap occurred) swap_date = device.get_sim_swap_date() if swap_date: print(f"SIM swap occurred: {swap_date.isoformat()}") # Verify if any SIM swap occurred if device.verify_sim_swap(): print("SIM swap detected") ``` -------------------------------- ### Check Device Connectivity and Roaming Status in Python Source: https://context7.com/nokia/network-as-code-py/llms.txt Checks the current connectivity status and roaming information of a device, including country code and name. It also demonstrates how to subscribe to connectivity status changes and manage these subscriptions. ```python # Get connectivity status status = device.get_connectivity() print(f"Connectivity: {status}") # Get roaming status with country information roaming = device.get_roaming() print(f"Roaming: {roaming.roaming}") print(f"Country code: {roaming.country_code}") print(f"Country name: {roaming.country_name}") # Subscribe to connectivity status changes from datetime import datetime, timedelta, timezone subscription = client.connectivity.subscribe( event_type="org.camaraproject.device-status.v0.connectivity-data", device=device, subscription_expire_time=datetime.now(timezone.utc) + timedelta(days=1), notification_url="https://example.com/notifications", notification_auth_token="your-auth-token" ) print(f"Subscription ID: {subscription.id}") print(f"Starts at: {subscription.starts_at}") print(f"Expires at: {subscription.expires_at}") # Delete subscription subscription.delete() ``` -------------------------------- ### KYC Age Verification (Python) Source: https://context7.com/nokia/network-as-code-py/llms.txt Verifies if a user meets a specified age threshold and optionally checks for parental controls and content locks. Requires providing user details like phone number, name, and birthdate. ```python # Verify age threshold age_result = device.verify_age( age_threshold=18, phone_number="+99999991000", name="John Doe", birthdate="1990-05-15", include_parental_control=True, include_content_lock=True ) # Check verification results print(f"Age verified: {age_result.verification_result}") print(f"Parental control active: {age_result.parental_control}") print(f"Content lock active: {age_result.content_lock}") ``` -------------------------------- ### KYC Identity Matching (Python) Source: https://context7.com/nokia/network-as-code-py/llms.txt Matches customer identity data against operator records. It allows matching various attributes such as phone number, ID document, name, address, birthdate, and email, and provides match scores for name and address. ```python # Match customer identity attributes match_result = device.match_customer( phone_number="+99999991000", id_document="66666666q", name="Federica Sanchez Arjona", given_name="Federica", family_name="Sanchez Arjona", middle_names="Sanchez", address="Tokyo-to Chiyoda-ku Iidabashi 3-10-10", street_name="Nicolas Salmeron", street_number="4", postal_code="1028460", region="Tokyo", locality="ZZZZ", country="JP", birthdate="1978-08-22", email="abc@example.com", gender="OTHER" ) # Access match results print(f"Name match: {match_result.name_match}") print(f"Name match score: {match_result.name_match_score}") print(f"Address match: {match_result.address_match}") ``` -------------------------------- ### Call Forwarding Detection (Python) Source: https://context7.com/nokia/network-as-code-py/llms.txt Checks for active call forwarding services on a device. Provides functions to verify unconditional call forwarding and retrieve detailed information about active call forwarding services. ```python # Verify unconditional call forwarding has_forwarding = device.verify_unconditional_forwarding() print(f"Unconditional forwarding active: {has_forwarding}") # Get detailed call forwarding service information services = device.get_call_forwarding() for service in services: print(f"Active service: {service}") ``` -------------------------------- ### Check Recent SIM Swap (Python) Source: https://context7.com/nokia/network-as-code-py/llms.txt Checks if a SIM swap has occurred on a device within a specified time frame. It utilizes the `verify_sim_swap` method, which takes `max_age` in seconds as input. Returns a boolean indicating if a recent SIM swap was detected. ```python # Check for recent SIM swap (within last 30 minutes) if device.verify_sim_swap(max_age=1800): print("Recent SIM swap detected!") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.